
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/matrices/matrices.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:26:20 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Matrices (linear algebra) &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="matrices.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Common Matrices" href="common.html" />
    <link rel="prev" title="Matrices" href="index.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="common.html" title="Common Matrices"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Matrices"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Matrices</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Matrices (linear algebra)</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.matrices.matrices">
<span id="matrices-linear-algebra"></span><h1>Matrices (linear algebra)<a class="headerlink" href="#module-sympy.matrices.matrices" title="Permalink to this headline">¶</a></h1>
<section id="creating-matrices">
<h2>Creating Matrices<a class="headerlink" href="#creating-matrices" title="Permalink to this headline">¶</a></h2>
<p>The linear algebra module is designed to be as simple as possible. First, we
import and declare our first <code class="docutils literal notranslate"><span class="pre">Matrix</span></code> object:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive.printing</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">wrap_line</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">eye</span><span class="p">,</span> <span class="n">zeros</span><span class="p">,</span> <span class="n">ones</span><span class="p">,</span> <span class="n">diag</span><span class="p">,</span> <span class="n">GramSchmidt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]]);</span> <span class="n">M</span>
<span class="go">[1  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">([</span><span class="n">M</span><span class="p">,</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)])</span>
<span class="go">[1  0  0 ]</span>
<span class="go">[        ]</span>
<span class="go">[0  0  0 ]</span>
<span class="go">[        ]</span>
<span class="go">[0  0  -1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span>
<span class="go">[1 2 3]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="go">[1]</span>
<span class="go">[ ]</span>
<span class="go">[2]</span>
<span class="go">[ ]</span>
<span class="go">[3]</span>
</pre></div>
</div>
<p>In addition to creating a matrix from a list of appropriately-sized lists
and/or matrices, SymPy also supports more advanced methods of matrix creation
including a single list of values and dimension inputs:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
<span class="go">[1  2  3]</span>
<span class="go">[       ]</span>
<span class="go">[4  5  6]</span>
</pre></div>
</div>
<p>More interesting (and useful), is the ability to use a 2-variable function
(or <code class="docutils literal notranslate"><span class="pre">lambda</span></code>) to create a matrix. Here we create an indicator function which
is 1 on the diagonal and then use it to make the identity matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="n">j</span><span class="p">:</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="mi">1</span>
<span class="gp">... </span>    <span class="k">else</span><span class="p">:</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="mi">0</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="go">[1  0  0  0]</span>
<span class="go">[          ]</span>
<span class="go">[0  1  0  0]</span>
<span class="go">[          ]</span>
<span class="go">[0  0  1  0]</span>
<span class="go">[          ]</span>
<span class="go">[0  0  0  1]</span>
</pre></div>
</div>
<p>Finally let’s use <code class="docutils literal notranslate"><span class="pre">lambda</span></code> to create a 1-line matrix with 1’s in the even
permutation entries:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">:</span> <span class="mi">1</span> <span class="o">-</span> <span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="p">)</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">[1  0  1  0]</span>
<span class="go">[          ]</span>
<span class="go">[0  1  0  1]</span>
<span class="go">[          ]</span>
<span class="go">[1  0  1  0]</span>
</pre></div>
</div>
<p>There are also a couple of special constructors for quick matrix construction:
<code class="docutils literal notranslate"><span class="pre">eye</span></code> is the identity matrix, <code class="docutils literal notranslate"><span class="pre">zeros</span></code> and <code class="docutils literal notranslate"><span class="pre">ones</span></code> for matrices of all
zeros and ones, respectively, and <code class="docutils literal notranslate"><span class="pre">diag</span></code> to put matrices or elements along
the diagonal:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eye</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="go">[1  0  0  0]</span>
<span class="go">[          ]</span>
<span class="go">[0  1  0  0]</span>
<span class="go">[          ]</span>
<span class="go">[0  0  1  0]</span>
<span class="go">[          ]</span>
<span class="go">[0  0  0  1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">zeros</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">[0  0]</span>
<span class="go">[    ]</span>
<span class="go">[0  0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">zeros</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">[0  0  0  0  0]</span>
<span class="go">[             ]</span>
<span class="go">[0  0  0  0  0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ones</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">[1  1  1]</span>
<span class="go">[       ]</span>
<span class="go">[1  1  1]</span>
<span class="go">[       ]</span>
<span class="go">[1  1  1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ones</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">[1  1  1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diag</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]]))</span>
<span class="go">[1  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  1  2]</span>
<span class="go">[       ]</span>
<span class="go">[0  3  4]</span>
</pre></div>
</div>
</section>
<section id="basic-manipulation">
<h2>Basic Manipulation<a class="headerlink" href="#basic-manipulation" title="Permalink to this headline">¶</a></h2>
<p>While learning to work with matrices, let’s choose one where the entries are
readily identifiable. One useful thing to know is that while matrices are
2-dimensional, the storage is not and so it is allowable - though one should be
careful - to access the entries as if they were a 1-d list.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span>
<span class="go">5</span>
</pre></div>
</div>
<p>Now, the more standard entry access is a pair of indices which will always
return the value at the corresponding row and column of the matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="go">5</span>
</pre></div>
</div>
<p>Since this is Python we’re also able to slice submatrices; slices always
give a matrix in return, even if the dimension is 1 x 1:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span>
<span class="go">[1  2]</span>
<span class="go">[    ]</span>
<span class="go">[4  5]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="go">[]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]</span>
<span class="go">[3]</span>
<span class="go">[ ]</span>
<span class="go">[6]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[:</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="go">[3]</span>
</pre></div>
</div>
<p>In the second example above notice that the slice 2:2 gives an empty range. Note
also (in keeping with 0-based indexing of Python) the first row/column is 0.</p>
<p>You cannot access rows or columns that are not present unless they
are in a slice:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[:,</span> <span class="mi">10</span><span class="p">]</span> <span class="c1"># the 10-th column (not there)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">IndexError</span>: <span class="n">Index out of range: a[[0, 10]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[:,</span> <span class="mi">10</span><span class="p">:</span><span class="mi">11</span><span class="p">]</span> <span class="c1"># the 10-th column (if there)</span>
<span class="go">[]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[:,</span> <span class="p">:</span><span class="mi">10</span><span class="p">]</span> <span class="c1"># all columns up to the 10-th</span>
<span class="go">[1  2  3]</span>
<span class="go">[       ]</span>
<span class="go">[4  5  6]</span>
</pre></div>
</div>
<p>Slicing an empty matrix works as long as you use a slice for the coordinate
that has no size:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[])[:,</span> <span class="mi">1</span><span class="p">]</span>
<span class="go">[]</span>
</pre></div>
</div>
<p>Slicing gives a copy of what is sliced, so modifications of one object
do not affect the other:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M2</span> <span class="o">=</span> <span class="n">M</span><span class="p">[:,</span> <span class="p">:]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M2</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">100</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">100</span>
<span class="go">False</span>
</pre></div>
</div>
<p>Notice that changing <code class="docutils literal notranslate"><span class="pre">M2</span></code> didn’t change <code class="docutils literal notranslate"><span class="pre">M</span></code>. Since we can slice, we can also assign
entries:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">],[</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">],[</span><span class="mi">9</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">11</span><span class="p">,</span><span class="mi">12</span><span class="p">],[</span><span class="mi">13</span><span class="p">,</span><span class="mi">14</span><span class="p">,</span><span class="mi">15</span><span class="p">,</span><span class="mi">16</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">[1   2   3   4 ]</span>
<span class="go">[              ]</span>
<span class="go">[5   6   7   8 ]</span>
<span class="go">[              ]</span>
<span class="go">[9   10  11  12]</span>
<span class="go">[              ]</span>
<span class="go">[13  14  15  16]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">M</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">[1   2   3   0 ]</span>
<span class="go">[              ]</span>
<span class="go">[5   6   7   8 ]</span>
<span class="go">[              ]</span>
<span class="go">[9   10  0   12]</span>
<span class="go">[              ]</span>
<span class="go">[13  14  15  16]</span>
</pre></div>
</div>
<p>as well as assign slices:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">],[</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">],[</span><span class="mi">9</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">11</span><span class="p">,</span><span class="mi">12</span><span class="p">],[</span><span class="mi">13</span><span class="p">,</span><span class="mi">14</span><span class="p">,</span><span class="mi">15</span><span class="p">,</span><span class="mi">16</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="p">[</span><span class="mi">2</span><span class="p">:,</span><span class="mi">2</span><span class="p">:]</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="k">lambda</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">:</span> <span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">[1   2   3  4]</span>
<span class="go">[            ]</span>
<span class="go">[5   6   7  8]</span>
<span class="go">[            ]</span>
<span class="go">[9   10  0  0]</span>
<span class="go">[            ]</span>
<span class="go">[13  14  0  0]</span>
</pre></div>
</div>
<p>All the standard arithmetic operations are supported:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],[</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">],[</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">-</span> <span class="n">M</span>
<span class="go">[0  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">+</span> <span class="n">M</span>
<span class="go">[2   4   6 ]</span>
<span class="go">[          ]</span>
<span class="go">[8   10  12]</span>
<span class="go">[          ]</span>
<span class="go">[14  16  18]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">*</span> <span class="n">M</span>
<span class="go">[30   36   42 ]</span>
<span class="go">[             ]</span>
<span class="go">[66   81   96 ]</span>
<span class="go">[             ]</span>
<span class="go">[102  126  150]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M2</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">,[</span><span class="mi">1</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">*</span><span class="n">M2</span>
<span class="go">[11]</span>
<span class="go">[  ]</span>
<span class="go">[29]</span>
<span class="go">[  ]</span>
<span class="go">[47]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">**</span><span class="mi">2</span>
<span class="go">[30   36   42 ]</span>
<span class="go">[             ]</span>
<span class="go">[66   81   96 ]</span>
<span class="go">[             ]</span>
<span class="go">[102  126  150]</span>
</pre></div>
</div>
<p>As well as some useful vector operations:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">row_del</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">[4  5  6]</span>
<span class="go">[       ]</span>
<span class="go">[7  8  9]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">col_del</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">[4  6]</span>
<span class="go">[    ]</span>
<span class="go">[7  9]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v2</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v3</span> <span class="o">=</span> <span class="n">v1</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">v2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v2</span><span class="p">)</span>
<span class="go">32</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v2</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v3</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v3</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p>Recall that the <code class="docutils literal notranslate"><span class="pre">row_del()</span></code> and <code class="docutils literal notranslate"><span class="pre">col_del()</span></code> operations don’t return a value - they
simply change the matrix object. We can also ‘’glue’’ together matrices of the
appropriate size:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M1</span> <span class="o">=</span> <span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M2</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M1</span><span class="o">.</span><span class="n">row_join</span><span class="p">(</span><span class="n">M2</span><span class="p">)</span>
<span class="go">[1  0  0  0  0  0  0]</span>
<span class="go">[                   ]</span>
<span class="go">[0  1  0  0  0  0  0]</span>
<span class="go">[                   ]</span>
<span class="go">[0  0  1  0  0  0  0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M3</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M1</span><span class="o">.</span><span class="n">col_join</span><span class="p">(</span><span class="n">M3</span><span class="p">)</span>
<span class="go">[1  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  1  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  1]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  0]</span>
</pre></div>
</div>
</section>
<section id="operations-on-entries">
<h2>Operations on entries<a class="headerlink" href="#operations-on-entries" title="Permalink to this headline">¶</a></h2>
<p>We are not restricted to having multiplication between two matrices:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">2</span><span class="o">*</span><span class="n">M</span>
<span class="go">[2  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  2  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  2]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">3</span><span class="o">*</span><span class="n">M</span>
<span class="go">[3  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  3  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  3]</span>
</pre></div>
</div>
<p>but we can also apply functions to our matrix entries using <code class="docutils literal notranslate"><span class="pre">applyfunc()</span></code>. Here we’ll declare a function that double any input number. Then we apply it to the 3x3 identity matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">applyfunc</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
<span class="go">[2  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  2  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  2]</span>
</pre></div>
</div>
<p>If you want to extract a common factor from a matrix you can do so by
applying <code class="docutils literal notranslate"><span class="pre">gcd</span></code> to the data of the matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">gcd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">]])</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="s1">&#39;ADJ&#39;</span><span class="p">);</span> <span class="n">m</span>
<span class="go">[  x*y       -y    ]</span>
<span class="go">[--------  --------]</span>
<span class="go">[ 2         2      ]</span>
<span class="go">[x *y - y  x *y - y]</span>
<span class="go">[                  ]</span>
<span class="go">[  -1         x    ]</span>
<span class="go">[--------  --------]</span>
<span class="go">[ 2         2      ]</span>
<span class="go">[x *y - y  x *y - y]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="n">_</span><span class="p">))</span>
<span class="go">   1</span>
<span class="go">--------</span>
<span class="go"> 2</span>
<span class="go">x *y - y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">/</span><span class="n">_</span>
<span class="go">[x*y  -y]</span>
<span class="go">[       ]</span>
<span class="go">[-1   x ]</span>
</pre></div>
</div>
<p>One more useful matrix-wide entry application function is the substitution function. Let’s declare a matrix with symbolic entries then substitute a value. Remember we can substitute anything - even another symbol!:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">*</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">[x  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  x  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  x]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">[4  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  4  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">[y  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  y  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  y]</span>
</pre></div>
</div>
</section>
<section id="linear-algebra">
<h2>Linear algebra<a class="headerlink" href="#linear-algebra" title="Permalink to this headline">¶</a></h2>
<p>Now that we have the basics out of the way, let’s see what we can do with the
actual matrices. Of course, one of the first things that comes to mind is the
determinant:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">((</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">det</span><span class="p">()</span>
<span class="go">-28</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M2</span> <span class="o">=</span> <span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M2</span><span class="o">.</span><span class="n">det</span><span class="p">()</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M3</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">((</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M3</span><span class="o">.</span><span class="n">det</span><span class="p">()</span>
<span class="go">0</span>
</pre></div>
</div>
<p>Another common operation is the inverse: In SymPy, this is computed by Gaussian
elimination by default (for dense matrices) but we can specify it be done by <span class="math notranslate nohighlight">\(LU\)</span>
decomposition as well:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M2</span><span class="o">.</span><span class="n">inv</span><span class="p">()</span>
<span class="go">[1  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  1  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M2</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s2">&quot;LU&quot;</span><span class="p">)</span>
<span class="go">[1  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  1  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s2">&quot;LU&quot;</span><span class="p">)</span>
<span class="go">[-3/14  1/14  1/2 ]</span>
<span class="go">[                 ]</span>
<span class="go">[-1/28  5/28  -1/4]</span>
<span class="go">[                 ]</span>
<span class="go">[ 3/7   -1/7   0  ]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">*</span> <span class="n">M</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s2">&quot;LU&quot;</span><span class="p">)</span>
<span class="go">[1  0  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  1  0]</span>
<span class="go">[       ]</span>
<span class="go">[0  0  1]</span>
</pre></div>
</div>
<p>We can perform a <span class="math notranslate nohighlight">\(QR\)</span> factorization which is handy for solving systems:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">],[</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="p">,</span> <span class="n">R</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">QRdecomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span>
<span class="go">[  ___     ___      ___ ]</span>
<span class="go">[\/ 6   -\/ 3    -\/ 2  ]</span>
<span class="go">[-----  -------  -------]</span>
<span class="go">[  6       3        2   ]</span>
<span class="go">[                       ]</span>
<span class="go">[  ___     ___      ___ ]</span>
<span class="go">[\/ 6   -\/ 3     \/ 2  ]</span>
<span class="go">[-----  -------   ----- ]</span>
<span class="go">[  6       3        2   ]</span>
<span class="go">[                       ]</span>
<span class="go">[  ___     ___          ]</span>
<span class="go">[\/ 6    \/ 3           ]</span>
<span class="go">[-----   -----      0   ]</span>
<span class="go">[  3       3            ]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span>
<span class="go">[           ___         ]</span>
<span class="go">[  ___  4*\/ 6       ___]</span>
<span class="go">[\/ 6   -------  2*\/ 6 ]</span>
<span class="go">[          3            ]</span>
<span class="go">[                       ]</span>
<span class="go">[          ___          ]</span>
<span class="go">[        \/ 3           ]</span>
<span class="go">[  0     -----      0   ]</span>
<span class="go">[          3            ]</span>
<span class="go">[                       ]</span>
<span class="go">[                   ___ ]</span>
<span class="go">[  0       0      \/ 2  ]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="o">*</span><span class="n">R</span>
<span class="go">[1  1  1]</span>
<span class="go">[       ]</span>
<span class="go">[1  1  3]</span>
<span class="go">[       ]</span>
<span class="go">[2  3  4]</span>
</pre></div>
</div>
<p>In addition to the solvers in the <code class="docutils literal notranslate"><span class="pre">solver.py</span></code> file, we can solve the system Ax=b
by passing the b vector to the matrix A’s LUsolve function. Here we’ll cheat a
little choose A and x then multiply to get b. Then we can solve for x and check
that it’s correct:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">8</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">]</span> <span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">,[</span><span class="mi">3</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">5</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">A</span><span class="o">*</span><span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">soln</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">LUsolve</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">soln</span>
<span class="go">[3]</span>
<span class="go">[ ]</span>
<span class="go">[7]</span>
<span class="go">[ ]</span>
<span class="go">[5]</span>
</pre></div>
</div>
<p>There’s also a nice Gram-Schmidt orthogonalizer which will take a set of
vectors and orthogonalize them with respect to another. There is an
optional argument which specifies whether or not the output should also be
normalized, it defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>. Let’s take some vectors and orthogonalize
them - one normalized and one not:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">L</span> <span class="o">=</span> <span class="p">[</span><span class="n">Matrix</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">]),</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">2</span><span class="p">]),</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">8</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">6</span><span class="p">])]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">out1</span> <span class="o">=</span> <span class="n">GramSchmidt</span><span class="p">(</span><span class="n">L</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">out2</span> <span class="o">=</span> <span class="n">GramSchmidt</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Let’s take a look at the vectors:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">out1</span><span class="p">:</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">Matrix([[2], [3], [5]])</span>
<span class="go">Matrix([[23/19], [63/19], [-47/19]])</span>
<span class="go">Matrix([[1692/353], [-1551/706], [-423/706]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">out2</span><span class="p">:</span>
<span class="gp">... </span>     <span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">Matrix([[sqrt(38)/19], [3*sqrt(38)/38], [5*sqrt(38)/38]])</span>
<span class="go">Matrix([[23*sqrt(6707)/6707], [63*sqrt(6707)/6707], [-47*sqrt(6707)/6707]])</span>
<span class="go">Matrix([[12*sqrt(706)/353], [-11*sqrt(706)/706], [-3*sqrt(706)/706]])</span>
</pre></div>
</div>
<p>We can spot-check their orthogonality with dot() and their normality with
norm():</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">out1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">out1</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">out1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">out1</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">out1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">out1</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">out2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">norm</span><span class="p">()</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">out2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">norm</span><span class="p">()</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">out2</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">norm</span><span class="p">()</span>
<span class="go">1</span>
</pre></div>
</div>
<p>So there is quite a bit that can be done with the module including eigenvalues,
eigenvectors, nullspace calculation, cofactor expansion tools, and so on. From
here one might want to look over the <code class="docutils literal notranslate"><span class="pre">matrices.py</span></code> file for all functionality.</p>
</section>
<section id="matrixdeterminant-class-reference">
<h2>MatrixDeterminant Class Reference<a class="headerlink" href="#matrixdeterminant-class-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixDeterminant">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">MatrixDeterminant</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L99-L152"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixDeterminant" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides basic matrix determinant operations. Should not be instantiated
directly. See <code class="docutils literal notranslate"><span class="pre">determinant.py</span></code> for their implementations.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixDeterminant.adjugate">
<span class="sig-name descname"><span class="pre">adjugate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'berkowitz'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L115-L116"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixDeterminant.adjugate" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the adjugate, or classical adjoint, of
a matrix.  That is, the transpose of the matrix of cofactors.</p>
<p><a class="reference external" href="https://en.wikipedia.org/wiki/Adjugate">https://en.wikipedia.org/wiki/Adjugate</a></p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>method</strong> : string, optional</p>
<blockquote>
<div><p>Method to use to find the cofactors, can be “bareiss”, “berkowitz” or
“lu”.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">adjugate</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[ 4, -2],</span>
<span class="go">[-3,  1]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.cofactor_matrix" title="sympy.matrices.matrices.MatrixDeterminant.cofactor_matrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cofactor_matrix</span></code></a>, <a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.transpose" title="sympy.matrices.common.MatrixCommon.transpose"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.common.MatrixCommon.transpose</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixDeterminant.charpoly">
<span class="sig-name descname"><span class="pre">charpoly</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">x='lambda'</span></em>, <em class="sig-param"><span class="pre">simplify=&lt;function</span> <span class="pre">simplify&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L118-L119"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixDeterminant.charpoly" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes characteristic polynomial det(x*I - M) where I is
the identity matrix.</p>
<p>A PurePoly is returned, so using different variables for <code class="docutils literal notranslate"><span class="pre">x</span></code> does
not affect the comparison or the polynomials:</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>x</strong> : string, optional</p>
<blockquote>
<div><p>Name for the “lambda” variable, defaults to “lambda”.</p>
</div></blockquote>
<p><strong>simplify</strong> : function, optional</p>
<blockquote>
<div><p>Simplification function to use on the characteristic polynomial
calculated. Defaults to <code class="docutils literal notranslate"><span class="pre">simplify</span></code>.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">charpoly</span><span class="p">()</span>
<span class="go">PurePoly(lambda**2 - lambda - 6, lambda, domain=&#39;ZZ&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">charpoly</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="n">M</span><span class="o">.</span><span class="n">charpoly</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">charpoly</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="n">M</span><span class="o">.</span><span class="n">charpoly</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Specifying <code class="docutils literal notranslate"><span class="pre">x</span></code> is optional; a symbol named <code class="docutils literal notranslate"><span class="pre">lambda</span></code> is used by
default (which looks good when pretty-printed in unicode):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">charpoly</span><span class="p">()</span><span class="o">.</span><span class="n">as_expr</span><span class="p">()</span>
<span class="go">lambda**2 - lambda - 6</span>
</pre></div>
</div>
<p>And if <code class="docutils literal notranslate"><span class="pre">x</span></code> clashes with an existing symbol, underscores will
be prepended to the name to make it unique:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">charpoly</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_expr</span><span class="p">()</span>
<span class="go">_x**2 - _x - 2*x</span>
</pre></div>
</div>
<p>Whether you pass a symbol or not, the generator can be obtained
with the gen attribute since it may not be the same as the symbol
that was passed:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">charpoly</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">gen</span>
<span class="go">_x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">charpoly</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">gen</span> <span class="o">==</span> <span class="n">x</span>
<span class="go">False</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The Samuelson-Berkowitz algorithm is used to compute
the characteristic polynomial efficiently and without any
division operations.  Thus the characteristic polynomial over any
commutative ring without zero divisors can be computed.</p>
<p>If the determinant det(x*I - M) can be found out easily as
in the case of an upper or a lower triangular matrix, then
instead of Samuelson-Berkowitz algorithm, eigenvalues are computed
and the characteristic polynomial with their help.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.det" title="sympy.matrices.matrices.MatrixDeterminant.det"><code class="xref py py-obj docutils literal notranslate"><span class="pre">det</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixDeterminant.cofactor">
<span class="sig-name descname"><span class="pre">cofactor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">j</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'berkowitz'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L121-L122"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixDeterminant.cofactor" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate the cofactor of an element.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>method</strong> : string, optional</p>
<blockquote>
<div><p>Method to use to find the cofactors, can be “bareiss”, “berkowitz” or
“lu”.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">cofactor</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">-3</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.cofactor_matrix" title="sympy.matrices.matrices.MatrixDeterminant.cofactor_matrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cofactor_matrix</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.minor" title="sympy.matrices.matrices.MatrixDeterminant.minor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">minor</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.minor_submatrix" title="sympy.matrices.matrices.MatrixDeterminant.minor_submatrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">minor_submatrix</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixDeterminant.cofactor_matrix">
<span class="sig-name descname"><span class="pre">cofactor_matrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'berkowitz'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L124-L125"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixDeterminant.cofactor_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a matrix containing the cofactor of each element.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>method</strong> : string, optional</p>
<blockquote>
<div><p>Method to use to find the cofactors, can be “bareiss”, “berkowitz” or
“lu”.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">cofactor_matrix</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[ 4, -3],</span>
<span class="go">[-2,  1]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.cofactor" title="sympy.matrices.matrices.MatrixDeterminant.cofactor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cofactor</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.minor" title="sympy.matrices.matrices.MatrixDeterminant.minor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">minor</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.minor_submatrix" title="sympy.matrices.matrices.MatrixDeterminant.minor_submatrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">minor_submatrix</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixDeterminant.det">
<span class="sig-name descname"><span class="pre">det</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'bareiss'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iszerofunc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L127-L128"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixDeterminant.det" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the determinant of a matrix if <code class="docutils literal notranslate"><span class="pre">M</span></code> is a concrete matrix object
otherwise return an expressions <code class="docutils literal notranslate"><span class="pre">Determinant(M)</span></code> if <code class="docutils literal notranslate"><span class="pre">M</span></code> is a
<code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code> or other expression.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>method</strong> : string, optional</p>
<blockquote>
<div><p>Specifies the algorithm used for computing the matrix determinant.</p>
<p>If the matrix is at most 3x3, a hard-coded formula is used and the
specified method is ignored. Otherwise, it defaults to
<code class="docutils literal notranslate"><span class="pre">'bareiss'</span></code>.</p>
<p>Also, if the matrix is an upper or a lower triangular matrix, determinant
is computed by simple multiplication of diagonal elements, and the
specified method is ignored.</p>
<p>If it is set to <code class="docutils literal notranslate"><span class="pre">'domain-ge'</span></code>, then Gaussian elimination method will
be used via using DomainMatrix.</p>
<p>If it is set to <code class="docutils literal notranslate"><span class="pre">'bareiss'</span></code>, Bareiss’ fraction-free algorithm will
be used.</p>
<p>If it is set to <code class="docutils literal notranslate"><span class="pre">'berkowitz'</span></code>, Berkowitz’ algorithm will be used.</p>
<p>Otherwise, if it is set to <code class="docutils literal notranslate"><span class="pre">'lu'</span></code>, LU decomposition will be used.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>For backward compatibility, legacy keys like “bareis” and
“det_lu” can still be used to indicate the corresponding
methods.
And the keys are also case-insensitive for now. However, it is
suggested to use the precise keys for specifying the method.</p>
</div>
</div></blockquote>
<p><strong>iszerofunc</strong> : FunctionType or None, optional</p>
<blockquote>
<div><p>If it is set to <code class="docutils literal notranslate"><span class="pre">None</span></code>, it will be defaulted to <code class="docutils literal notranslate"><span class="pre">_iszero</span></code> if the
method is set to <code class="docutils literal notranslate"><span class="pre">'bareiss'</span></code>, and <code class="docutils literal notranslate"><span class="pre">_is_zero_after_expand_mul</span></code> if
the method is set to <code class="docutils literal notranslate"><span class="pre">'lu'</span></code>.</p>
<p>It can also accept any user-specified zero testing function, if it
is formatted as a function which accepts a single symbolic argument
and returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if it is tested as zero and <code class="docutils literal notranslate"><span class="pre">False</span></code> if it
tested as non-zero, and also <code class="docutils literal notranslate"><span class="pre">None</span></code> if it is undecidable.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>det</strong> : Basic</p>
<blockquote>
<div><p>Result of determinant.</p>
</div></blockquote>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><strong>ValueError</strong></p>
<blockquote>
<div><p>If unrecognized keys are given for <code class="docutils literal notranslate"><span class="pre">method</span></code> or <code class="docutils literal notranslate"><span class="pre">iszerofunc</span></code>.</p>
</div></blockquote>
<p><strong>NonSquareMatrixError</strong></p>
<blockquote>
<div><p>If attempted to calculate determinant from a non-square matrix.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">eye</span><span class="p">,</span> <span class="n">det</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I3</span> <span class="o">=</span> <span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">det</span><span class="p">(</span><span class="n">I3</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">det</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
<span class="go">-2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">det</span><span class="p">(</span><span class="n">M</span><span class="p">)</span> <span class="o">==</span> <span class="n">M</span><span class="o">.</span><span class="n">det</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">det</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s2">&quot;domain-ge&quot;</span><span class="p">)</span>
<span class="go">-2</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixDeterminant.minor">
<span class="sig-name descname"><span class="pre">minor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">j</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'berkowitz'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L133-L134"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixDeterminant.minor" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the (i,j) minor of <code class="docutils literal notranslate"><span class="pre">M</span></code>.  That is,
return the determinant of the matrix obtained by deleting
the <span class="math notranslate nohighlight">\(i\)</span>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>i, j</strong> : int</p>
<blockquote>
<div><p>The row and column to exclude to obtain the submatrix.</p>
</div></blockquote>
<p><strong>method</strong> : string, optional</p>
<blockquote>
<div><p>Method to use to find the determinant of the submatrix, can be
“bareiss”, “berkowitz” or “lu”.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">minor</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">-12</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.minor_submatrix" title="sympy.matrices.matrices.MatrixDeterminant.minor_submatrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">minor_submatrix</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.cofactor" title="sympy.matrices.matrices.MatrixDeterminant.cofactor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cofactor</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.det" title="sympy.matrices.matrices.MatrixDeterminant.det"><code class="xref py py-obj docutils literal notranslate"><span class="pre">det</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixDeterminant.minor_submatrix">
<span class="sig-name descname"><span class="pre">minor_submatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">j</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L136-L137"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixDeterminant.minor_submatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the submatrix obtained by removing the <span class="math notranslate nohighlight">\(i\)</span> (works with Pythonic negative indices).</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>i, j</strong> : int</p>
<blockquote>
<div><p>The row and column to exclude to obtain the submatrix.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">minor_submatrix</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1, 3],</span>
<span class="go">[7, 9]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.minor" title="sympy.matrices.matrices.MatrixDeterminant.minor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">minor</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.cofactor" title="sympy.matrices.matrices.MatrixDeterminant.cofactor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cofactor</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixDeterminant.per">
<span class="sig-name descname"><span class="pre">per</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L130-L131"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixDeterminant.per" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the permanent of a matrix. Unlike determinant,
permanent is defined for both square and non-square matrices.</p>
<p>For an m x n matrix, with m less than or equal to n,
it is given as the sum over the permutations s of size
less than or equal to m on [1, 2, … n] of the product
from i = 1 to m of M[i, s[i]]. Taking the transpose will
not affect the value of the permanent.</p>
<p>In the case of a square matrix, this is the same as the permutation
definition of the determinant, but it does not take the sign of the
permutation into account. Computing the permanent with this definition
is quite inefficient, so here the Ryser formula is used.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">per</span><span class="p">()</span>
<span class="go">450</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">7</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">per</span><span class="p">()</span>
<span class="go">13</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r525"><span class="brackets"><a class="fn-backref" href="#id1">R525</a></span></dt>
<dd><p>Prof. Frank Ben’s notes: <a class="reference external" href="https://math.berkeley.edu/~bernd/ban275.pdf">https://math.berkeley.edu/~bernd/ban275.pdf</a></p>
</dd>
<dt class="label" id="r526"><span class="brackets"><a class="fn-backref" href="#id2">R526</a></span></dt>
<dd><p>Wikipedia article on Permanent: <a class="reference external" href="https://en.wikipedia.org/wiki/Permanent_(mathematics">https://en.wikipedia.org/wiki/Permanent_(mathematics</a>)</p>
</dd>
<dt class="label" id="r527"><span class="brackets"><a class="fn-backref" href="#id3">R527</a></span></dt>
<dd><p><a class="reference external" href="https://reference.wolfram.com/language/ref/Permanent.html">https://reference.wolfram.com/language/ref/Permanent.html</a></p>
</dd>
<dt class="label" id="r528"><span class="brackets"><a class="fn-backref" href="#id4">R528</a></span></dt>
<dd><p>Permanent of a rectangular matrix : <a class="reference external" href="https://arxiv.org/pdf/0904.3251.pdf">https://arxiv.org/pdf/0904.3251.pdf</a></p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</section>
<section id="matrixreductions-class-reference">
<h2>MatrixReductions Class Reference<a class="headerlink" href="#matrixreductions-class-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixReductions">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">MatrixReductions</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L155-L339"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixReductions" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides basic matrix row/column operations. Should not be instantiated
directly. See <code class="docutils literal notranslate"><span class="pre">reductions.py</span></code> for some of their implementations.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixReductions.echelon_form">
<span class="sig-name descname"><span class="pre">echelon_form</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em>, <em class="sig-param"><span class="pre">simplify=False</span></em>, <em class="sig-param"><span class="pre">with_pivots=False</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L159-L161"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixReductions.echelon_form" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a matrix row-equivalent to <code class="docutils literal notranslate"><span class="pre">M</span></code> that is in echelon form. Note
that echelon form of a matrix is <em>not</em> unique, however, properties like the
row space and the null space are preserved.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">echelon_form</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[1,  2],</span>
<span class="go">[0, -2]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixReductions.elementary_col_op">
<span class="sig-name descname"><span class="pre">elementary_col_op</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">op</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'n-&gt;kn'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">col</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">col1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">col2</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L281-L309"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixReductions.elementary_col_op" title="Permalink to this definition">¶</a></dt>
<dd><p>Performs the elementary column operation <span class="math notranslate nohighlight">\(op\)</span>.</p>
<p><span class="math notranslate nohighlight">\(op\)</span> may be one of</p>
<blockquote>
<div><ul class="simple">
<li><p>“n-&gt;kn” (column n goes to k*n)</p></li>
<li><p>“n&lt;-&gt;m” (swap column n and column m)</p></li>
<li><p>“n-&gt;n+km” (column n goes to column n + k*column m)</p></li>
</ul>
</div></blockquote>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>op</strong> : string; the elementary row operation</p>
<p><strong>col</strong> : the column to apply the column operation</p>
<p><strong>k</strong> : the multiple to apply in the column operation</p>
<p><strong>col1</strong> : one column of a column swap</p>
<p><strong>col2</strong> : second column of a column swap or column “m” in the column operation</p>
<blockquote>
<div><p>“n-&gt;n+km”</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixReductions.elementary_row_op">
<span class="sig-name descname"><span class="pre">elementary_row_op</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">op</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'n-&gt;kn'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">row</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">row1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">row2</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L311-L339"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixReductions.elementary_row_op" title="Permalink to this definition">¶</a></dt>
<dd><p>Performs the elementary row operation <span class="math notranslate nohighlight">\(op\)</span>.</p>
<p><span class="math notranslate nohighlight">\(op\)</span> may be one of</p>
<blockquote>
<div><ul class="simple">
<li><p>“n-&gt;kn” (row n goes to k*n)</p></li>
<li><p>“n&lt;-&gt;m” (swap row n and row m)</p></li>
<li><p>“n-&gt;n+km” (row n goes to row n + k*row m)</p></li>
</ul>
</div></blockquote>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>op</strong> : string; the elementary row operation</p>
<p><strong>row</strong> : the row to apply the row operation</p>
<p><strong>k</strong> : the multiple to apply in the row operation</p>
<p><strong>row1</strong> : one row of a row swap</p>
<p><strong>row2</strong> : second row of a row swap or row “m” in the row operation</p>
<blockquote>
<div><p>“n-&gt;n+km”</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixReductions.is_echelon">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_echelon</span></span><a class="headerlink" href="#sympy.matrices.matrices.MatrixReductions.is_echelon" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <span class="math notranslate nohighlight">\(True\)</span> if the matrix is in echelon form. That is, all rows of
zeros are at the bottom, and below each leading non-zero in a row are
exclusively zeros.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixReductions.rank">
<span class="sig-name descname"><span class="pre">rank</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em>, <em class="sig-param"><span class="pre">simplify=False</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L167-L168"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixReductions.rank" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the rank of a matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">rank</span><span class="p">()</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="o">.</span><span class="n">rank</span><span class="p">()</span>
<span class="go">2</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixReductions.rref">
<span class="sig-name descname"><span class="pre">rref</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em>, <em class="sig-param"><span class="pre">simplify=False</span></em>, <em class="sig-param"><span class="pre">pivots=True</span></em>, <em class="sig-param"><span class="pre">normalize_last=True</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L170-L173"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixReductions.rref" title="Permalink to this definition">¶</a></dt>
<dd><p>Return reduced row-echelon form of matrix and indices of pivot vars.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>iszerofunc</strong> : Function</p>
<blockquote>
<div><p>A function used for detecting whether an element can
act as a pivot.  <code class="docutils literal notranslate"><span class="pre">lambda</span> <span class="pre">x:</span> <span class="pre">x.is_zero</span></code> is used by default.</p>
</div></blockquote>
<p><strong>simplify</strong> : Function</p>
<blockquote>
<div><p>A function used to simplify elements when looking for a pivot.
By default SymPy’s <code class="docutils literal notranslate"><span class="pre">simplify</span></code> is used.</p>
</div></blockquote>
<p><strong>pivots</strong> : True or False</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">True</span></code>, a tuple containing the row-reduced matrix and a tuple
of pivot columns is returned.  If <code class="docutils literal notranslate"><span class="pre">False</span></code> just the row-reduced
matrix is returned.</p>
</div></blockquote>
<p><strong>normalize_last</strong> : True or False</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">True</span></code>, no pivots are normalized to <span class="math notranslate nohighlight">\(1\)</span> until after all
entries above and below each pivot are zeroed.  This means the row
reduction algorithm is fraction free until the very last step.
If <code class="docutils literal notranslate"><span class="pre">False</span></code>, the naive row reduction procedure is used where
each pivot is normalized to be <span class="math notranslate nohighlight">\(1\)</span> before row operations are
used to zero above and below the pivot.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">rref</span><span class="p">()</span>
<span class="go">(Matrix([</span>
<span class="go">[1, 0],</span>
<span class="go">[0, 1]]), (0, 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rref_matrix</span><span class="p">,</span> <span class="n">rref_pivots</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">rref</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rref_matrix</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0],</span>
<span class="go">[0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rref_pivots</span>
<span class="go">(0, 1)</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The default value of <code class="docutils literal notranslate"><span class="pre">normalize_last=True</span></code> can provide significant
speedup to row reduction, especially on matrices with symbols.  However,
if you depend on the form row reduction algorithm leaves entries
of the matrix, set <code class="docutils literal notranslate"><span class="pre">noramlize_last=False</span></code></p>
</dd></dl>

</dd></dl>

</section>
<section id="matrixsubspaces-class-reference">
<h2>MatrixSubspaces Class Reference<a class="headerlink" href="#matrixsubspaces-class-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixSubspaces">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">MatrixSubspaces</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L342-L367"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixSubspaces" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides methods relating to the fundamental subspaces of a matrix.
Should not be instantiated directly. See <code class="docutils literal notranslate"><span class="pre">subspaces.py</span></code> for their
implementations.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixSubspaces.columnspace">
<span class="sig-name descname"><span class="pre">columnspace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">simplify</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L347-L348"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixSubspaces.columnspace" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of vectors (Matrix objects) that span columnspace of <code class="docutils literal notranslate"><span class="pre">M</span></code></p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">6</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">Matrix([</span>
<span class="go">[ 1,  3, 0],</span>
<span class="go">[-2, -6, 0],</span>
<span class="go">[ 3,  9, 6]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">columnspace</span><span class="p">()</span>
<span class="go">[Matrix([</span>
<span class="go">[ 1],</span>
<span class="go">[-2],</span>
<span class="go">[ 3]]), Matrix([</span>
<span class="go">[0],</span>
<span class="go">[0],</span>
<span class="go">[6]])]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixSubspaces.nullspace" title="sympy.matrices.matrices.MatrixSubspaces.nullspace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">nullspace</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixSubspaces.rowspace" title="sympy.matrices.matrices.MatrixSubspaces.rowspace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rowspace</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixSubspaces.nullspace">
<span class="sig-name descname"><span class="pre">nullspace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">simplify=False</span></em>, <em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L350-L351"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixSubspaces.nullspace" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns list of vectors (Matrix objects) that span nullspace of <code class="docutils literal notranslate"><span class="pre">M</span></code></p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">6</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">Matrix([</span>
<span class="go">[ 1,  3, 0],</span>
<span class="go">[-2, -6, 0],</span>
<span class="go">[ 3,  9, 6]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">nullspace</span><span class="p">()</span>
<span class="go">[Matrix([</span>
<span class="go">[-3],</span>
<span class="go">[ 1],</span>
<span class="go">[ 0]])]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixSubspaces.columnspace" title="sympy.matrices.matrices.MatrixSubspaces.columnspace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">columnspace</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixSubspaces.rowspace" title="sympy.matrices.matrices.MatrixSubspaces.rowspace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rowspace</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixSubspaces.orthogonalize">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">orthogonalize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">vecs</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L359-L360"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixSubspaces.orthogonalize" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply the Gram-Schmidt orthogonalization procedure
to vectors supplied in <code class="docutils literal notranslate"><span class="pre">vecs</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>vecs</strong></p>
<blockquote>
<div><p>vectors to be made orthogonal</p>
</div></blockquote>
<p><strong>normalize</strong> : bool</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">True</span></code>, return an orthonormal basis.</p>
</div></blockquote>
<p><strong>rankcheck</strong> : bool</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">True</span></code>, the computation does not stop when encountering
linearly dependent vectors.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">False</span></code>, it will raise <code class="docutils literal notranslate"><span class="pre">ValueError</span></code> when any zero
or linearly dependent vectors are found.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>list</p>
<blockquote>
<div><p>List of orthogonal (or orthonormal) basis vectors.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">I</span><span class="p">,</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="p">[</span><span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="n">I</span><span class="p">]),</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="n">I</span><span class="p">])]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="o">.</span><span class="n">orthogonalize</span><span class="p">(</span><span class="o">*</span><span class="n">v</span><span class="p">)</span>
<span class="go">[Matrix([</span>
<span class="go">[1],</span>
<span class="go">[I]]), Matrix([</span>
<span class="go">[ 1],</span>
<span class="go">[-I]])]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRdecomposition" title="sympy.matrices.matrices.MatrixBase.QRdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MatrixBase.QRdecomposition</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r529"><span class="brackets"><a class="fn-backref" href="#id5">R529</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Gram–Schmidt_process">https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixSubspaces.rowspace">
<span class="sig-name descname"><span class="pre">rowspace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">simplify</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L353-L354"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixSubspaces.rowspace" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of vectors that span the row space of <code class="docutils literal notranslate"><span class="pre">M</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">6</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">Matrix([</span>
<span class="go">[ 1,  3, 0],</span>
<span class="go">[-2, -6, 0],</span>
<span class="go">[ 3,  9, 6]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">rowspace</span><span class="p">()</span>
<span class="go">[Matrix([[1, 3, 0]]), Matrix([[0, 0, 6]])]</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="matrixeigen-class-reference">
<h2>MatrixEigen Class Reference<a class="headerlink" href="#matrixeigen-class-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">MatrixEigen</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L370-L437"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides basic matrix eigenvalue/vector operations.
Should not be instantiated directly. See <code class="docutils literal notranslate"><span class="pre">eigen.py</span></code> for their
implementations.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.bidiagonal_decomposition">
<span class="sig-name descname"><span class="pre">bidiagonal_decomposition</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">upper</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L392-L393"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.bidiagonal_decomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns (U,B,V.H)</p>
<p><span class="math notranslate nohighlight">\(A = UBV^{H}\)</span></p>
<p>where A is the input matrix, and B is its Bidiagonalized form</p>
<p>Note: Bidiagonal Computation can hang for symbolic matrices.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>upper</strong> : bool. Whether to do upper bidiagnalization or lower.</p>
<blockquote>
<div><p>True for upper and False for lower.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">References</p>
<ol class="arabic simple">
<li><p>Algorith 5.4.2, Matrix computations by Golub and Van Loan, 4th edition</p></li>
<li><p>Complex Matrix Bidiagonalization : <a class="reference external" href="https://github.com/vslobody/Householder-Bidiagonalization">https://github.com/vslobody/Householder-Bidiagonalization</a></p></li>
</ol>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.bidiagonalize">
<span class="sig-name descname"><span class="pre">bidiagonalize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">upper</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L389-L390"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.bidiagonalize" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <span class="math notranslate nohighlight">\(B\)</span>, the Bidiagonalized form of the input matrix.</p>
<p>Note: Bidiagonal Computation can hang for symbolic matrices.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>upper</strong> : bool. Whether to do upper bidiagnalization or lower.</p>
<blockquote>
<div><p>True for upper and False for lower.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">References</p>
<ol class="arabic simple">
<li><p>Algorith 5.4.2, Matrix computations by Golub and Van Loan, 4th edition</p></li>
<li><p>Complex Matrix Bidiagonalization : <a class="reference external" href="https://github.com/vslobody/Householder-Bidiagonalization">https://github.com/vslobody/Householder-Bidiagonalization</a></p></li>
</ol>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.diagonalize">
<span class="sig-name descname"><span class="pre">diagonalize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">reals_only</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sort</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">normalize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L385-L387"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.diagonalize" title="Permalink to this definition">¶</a></dt>
<dd><p>Return (P, D), where D is diagonal and</p>
<blockquote>
<div><p>D = P^-1 * M * P</p>
</div></blockquote>
<p>where M is current matrix.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>reals_only</strong> : bool. Whether to throw an error if complex numbers are need</p>
<blockquote>
<div><p>to diagonalize. (Default: False)</p>
</div></blockquote>
<p><strong>sort</strong> : bool. Sort the eigenvalues along the diagonal. (Default: False)</p>
<p><strong>normalize</strong> : bool. If True, normalize the columns of P. (Default: False)</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">4</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span>
<span class="go">Matrix([</span>
<span class="go">[1,  2, 0],</span>
<span class="go">[0,  3, 0],</span>
<span class="go">[2, -4, 2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">P</span><span class="p">,</span> <span class="n">D</span><span class="p">)</span> <span class="o">=</span> <span class="n">M</span><span class="o">.</span><span class="n">diagonalize</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 2, 0],</span>
<span class="go">[0, 0, 3]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span>
<span class="go">Matrix([</span>
<span class="go">[-1, 0, -1],</span>
<span class="go">[ 0, 0, -1],</span>
<span class="go">[ 2, 1,  2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="o">.</span><span class="n">inv</span><span class="p">()</span> <span class="o">*</span> <span class="n">M</span> <span class="o">*</span> <span class="n">P</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 2, 0],</span>
<span class="go">[0, 0, 3]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.is_diagonal" title="sympy.matrices.common.MatrixCommon.is_diagonal"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_diagonal</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixEigen.is_diagonalizable" title="sympy.matrices.matrices.MatrixEigen.is_diagonalizable"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_diagonalizable</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.eigenvals">
<span class="sig-name descname"><span class="pre">eigenvals</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">error_when_incomplete</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">flags</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L375-L376"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.eigenvals" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute eigenvalues of the matrix.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>error_when_incomplete</strong> : bool, optional</p>
<blockquote>
<div><p>If it is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, it will raise an error if not all
eigenvalues are computed. This is caused by <code class="docutils literal notranslate"><span class="pre">roots</span></code> not returning
a full list of eigenvalues.</p>
</div></blockquote>
<p><strong>simplify</strong> : bool or function, optional</p>
<blockquote>
<div><p>If it is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, it attempts to return the most
simplified form of expressions returned by applying default
simplification method in every routine.</p>
<p>If it is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, it will skip simplification in this
particular routine to save computation resources.</p>
<p>If a function is passed to, it will attempt to apply
the particular function as simplification method.</p>
</div></blockquote>
<p><strong>rational</strong> : bool, optional</p>
<blockquote>
<div><p>If it is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, every floating point numbers would be
replaced with rationals before computation. It can solve some
issues of <code class="docutils literal notranslate"><span class="pre">roots</span></code> routine not working well with floats.</p>
</div></blockquote>
<p><strong>multiple</strong> : bool, optional</p>
<blockquote>
<div><p>If it is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, the result will be in the form of a
list.</p>
<p>If it is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, the result will be in the form of a
dictionary.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>eigs</strong> : list or dict</p>
<blockquote>
<div><p>Eigenvalues of a matrix. The return format would be specified by
the key <code class="docutils literal notranslate"><span class="pre">multiple</span></code>.</p>
</div></blockquote>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><strong>MatrixError</strong></p>
<blockquote>
<div><p>If not enough roots had got computed.</p>
</div></blockquote>
<p><strong>NonSquareMatrixError</strong></p>
<blockquote>
<div><p>If attempted to compute eigenvalues from a non-square matrix.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">eigenvals</span><span class="p">()</span>
<span class="go">{-1: 1, 0: 1, 2: 1}</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Eigenvalues of a matrix <span class="math notranslate nohighlight">\(A\)</span> can be computed by solving a matrix
equation <span class="math notranslate nohighlight">\(\det(A - \lambda I) = 0\)</span></p>
<p>It’s not always possible to return radical solutions for
eigenvalues for matrices larger than <span class="math notranslate nohighlight">\(4, 4\)</span> shape due to
Abel-Ruffini theorem.</p>
<p>If there is no radical solution is found for the eigenvalue,
it may return eigenvalues in the form of
<a class="reference internal" href="../polys/reference.html#sympy.polys.rootoftools.ComplexRootOf" title="sympy.polys.rootoftools.ComplexRootOf"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.polys.rootoftools.ComplexRootOf</span></code></a>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixDeterminant.charpoly" title="sympy.matrices.matrices.MatrixDeterminant.charpoly"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MatrixDeterminant.charpoly</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixEigen.eigenvects" title="sympy.matrices.matrices.MatrixEigen.eigenvects"><code class="xref py py-obj docutils literal notranslate"><span class="pre">eigenvects</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.eigenvects">
<span class="sig-name descname"><span class="pre">eigenvects</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">error_when_incomplete=True</span></em>, <em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em>, <em class="sig-param"><span class="pre">**flags</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L378-L380"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.eigenvects" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute eigenvectors of the matrix.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>error_when_incomplete</strong> : bool, optional</p>
<blockquote>
<div><p>Raise an error when not all eigenvalues are computed. This is
caused by <code class="docutils literal notranslate"><span class="pre">roots</span></code> not returning a full list of eigenvalues.</p>
</div></blockquote>
<p><strong>iszerofunc</strong> : function, optional</p>
<blockquote>
<div><p>Specifies a zero testing function to be used in <code class="docutils literal notranslate"><span class="pre">rref</span></code>.</p>
<p>Default value is <code class="docutils literal notranslate"><span class="pre">_iszero</span></code>, which uses SymPy’s naive and fast
default assumption handler.</p>
<p>It can also accept any user-specified zero testing function, if it
is formatted as a function which accepts a single symbolic argument
and returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if it is tested as zero and <code class="docutils literal notranslate"><span class="pre">False</span></code> if it
is tested as non-zero, and <code class="docutils literal notranslate"><span class="pre">None</span></code> if it is undecidable.</p>
</div></blockquote>
<p><strong>simplify</strong> : bool or function, optional</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="docutils literal notranslate"><span class="pre">as_content_primitive()</span></code> will be used to tidy up
normalization artifacts.</p>
<p>It will also be used by the <code class="docutils literal notranslate"><span class="pre">nullspace</span></code> routine.</p>
</div></blockquote>
<p><strong>chop</strong> : bool or positive number, optional</p>
<blockquote>
<div><p>If the matrix contains any Floats, they will be changed to Rationals
for computation purposes, but the answers will be returned after
being evaluated with evalf. The <code class="docutils literal notranslate"><span class="pre">chop</span></code> flag is passed to <code class="docutils literal notranslate"><span class="pre">evalf</span></code>.
When <code class="docutils literal notranslate"><span class="pre">chop=True</span></code> a default precision will be used; a number will
be interpreted as the desired level of precision.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>ret</strong> : [(eigenval, multiplicity, eigenspace), …]</p>
<blockquote>
<div><p>A ragged list containing tuples of data obtained by <code class="docutils literal notranslate"><span class="pre">eigenvals</span></code>
and <code class="docutils literal notranslate"><span class="pre">nullspace</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">eigenspace</span></code> is a list containing the <code class="docutils literal notranslate"><span class="pre">eigenvector</span></code> for each
eigenvalue.</p>
<p><code class="docutils literal notranslate"><span class="pre">eigenvector</span></code> is a vector in the form of a <code class="docutils literal notranslate"><span class="pre">Matrix</span></code>. e.g.
a vector of length 3 is returned as <code class="docutils literal notranslate"><span class="pre">Matrix([a_1,</span> <span class="pre">a_2,</span> <span class="pre">a_3])</span></code>.</p>
</div></blockquote>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><strong>NotImplementedError</strong></p>
<blockquote>
<div><p>If failed to compute nullspace.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">eigenvects</span><span class="p">()</span>
<span class="go">[(-1, 1, [Matrix([</span>
<span class="go">[-1],</span>
<span class="go">[ 1],</span>
<span class="go">[ 0]])]), (0, 1, [Matrix([</span>
<span class="go">[ 0],</span>
<span class="go">[-1],</span>
<span class="go">[ 1]])]), (2, 1, [Matrix([</span>
<span class="go">[2/3],</span>
<span class="go">[1/3],</span>
<span class="go">[  1]])])]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixEigen.eigenvals" title="sympy.matrices.matrices.MatrixEigen.eigenvals"><code class="xref py py-obj docutils literal notranslate"><span class="pre">eigenvals</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixSubspaces.nullspace" title="sympy.matrices.matrices.MatrixSubspaces.nullspace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MatrixSubspaces.nullspace</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.is_diagonalizable">
<span class="sig-name descname"><span class="pre">is_diagonalizable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">reals_only</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L382-L383"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.is_diagonalizable" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if a matrix is diagonalizable.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>reals_only</strong> : bool, optional</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">True</span></code>, it tests whether the matrix can be diagonalized
to contain only real numbers on the diagonal.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">False</span></code>, it tests whether the matrix can be diagonalized
at all, even with numbers that may not be real.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>Example of a diagonalizable matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">4</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">is_diagonalizable</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Example of a non-diagonalizable matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">is_diagonalizable</span><span class="p">()</span>
<span class="go">False</span>
</pre></div>
</div>
<p>Example of a matrix that is diagonalized in terms of non-real entries:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">is_diagonalizable</span><span class="p">(</span><span class="n">reals_only</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">is_diagonalizable</span><span class="p">(</span><span class="n">reals_only</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.is_diagonal" title="sympy.matrices.common.MatrixCommon.is_diagonal"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_diagonal</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixEigen.diagonalize" title="sympy.matrices.matrices.MatrixEigen.diagonalize"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonalize</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.is_indefinite">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_indefinite</span></span><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.is_indefinite" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds out the definiteness of a matrix.</p>
<p class="rubric">Explanation</p>
<p>A square real matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \geq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(x^T A x &lt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \leq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero real vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(x^T A x &gt; 0 &gt; y^T A y\)</span>.</p></li>
</ul>
<p>A square complex matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \geq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &lt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \leq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero complex vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0 &gt; \text{re}(y^H A y)\)</span>.</p></li>
</ul>
<p>A matrix need not be symmetric or hermitian to be positive definite.</p>
<ul class="simple">
<li><p>A real non-symmetric matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> is positive definite.</p></li>
<li><p>A complex non-hermitian matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span> is positive definite.</p></li>
</ul>
<p>And this extension can apply for all the definitions above.</p>
<p>However, for complex cases, you can restrict the definition of
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span> to <span class="math notranslate nohighlight">\(x^H A x &gt; 0\)</span> and require the matrix
to be hermitian.
But we do not present this restriction for computation because you
can check <code class="docutils literal notranslate"><span class="pre">M.is_hermitian</span></code> independently with this and use
the same procedure.</p>
<p class="rubric">Examples</p>
<p>An example of symmetric positive definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.plotting</span> <span class="kn">import</span> <span class="n">plot3d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-1.png">png</a>, <a class="reference external" href="matrices-1.hires.png">hires.png</a>, <a class="reference external" href="matrices-1.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-1.png" class="plot-directive" src="../../_images/matrices-1.png" />
</figure>
<p>An example of symmetric positive semidefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-2.png">png</a>, <a class="reference external" href="matrices-2.hires.png">hires.png</a>, <a class="reference external" href="matrices-2.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-2.png" class="plot-directive" src="../../_images/matrices-2.png" />
</figure>
<p>An example of symmetric negative definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_semidefinite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-3.png">png</a>, <a class="reference external" href="matrices-3.hires.png">hires.png</a>, <a class="reference external" href="matrices-3.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-3.png" class="plot-directive" src="../../_images/matrices-3.png" />
</figure>
<p>An example of symmetric indefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-4.png">png</a>, <a class="reference external" href="matrices-4.hires.png">hires.png</a>, <a class="reference external" href="matrices-4.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-4.png" class="plot-directive" src="../../_images/matrices-4.png" />
</figure>
<p>An example of non-symmetric positive definite matrix.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-5.png">png</a>, <a class="reference external" href="matrices-5.hires.png">hires.png</a>, <a class="reference external" href="matrices-5.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-5.png" class="plot-directive" src="../../_images/matrices-5.png" />
</figure>
<p class="rubric">Notes</p>
<p>Although some people trivialize the definition of positive definite
matrices only for symmetric or hermitian matrices, this restriction
is not correct because it does not classify all instances of
positive definite matrices from the definition <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span> or
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>.</p>
<p>For instance, <code class="docutils literal notranslate"><span class="pre">Matrix([[1,</span> <span class="pre">2],</span> <span class="pre">[-2,</span> <span class="pre">1]])</span></code> presented in
the example above is an example of real positive definite matrix
that is not symmetric.</p>
<p>However, since the following formula holds true;</p>
<div class="math notranslate nohighlight">
\[\text{re}(x^H A x) &gt; 0 \iff
\text{re}(x^H \frac{A + A^H}{2} x) &gt; 0\]</div>
<p>We can classify all positive definite matrices that may or may not
be symmetric or hermitian by transforming the matrix to
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> or <span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span>
(which is guaranteed to be always real symmetric or complex
hermitian) and we can defer most of the studies to symmetric or
hermitian positive definite matrices.</p>
<p>But it is a different problem for the existance of Cholesky
decomposition. Because even though a non symmetric or a non
hermitian matrix can be positive definite, Cholesky or LDL
decomposition does not exist because the decompositions require the
matrix to be symmetric or hermitian.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r530"><span class="brackets"><a class="fn-backref" href="#id6">R530</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues">https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues</a></p>
</dd>
<dt class="label" id="r531"><span class="brackets"><a class="fn-backref" href="#id7">R531</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/PositiveDefiniteMatrix.html">http://mathworld.wolfram.com/PositiveDefiniteMatrix.html</a></p>
</dd>
<dt class="label" id="r532"><span class="brackets"><a class="fn-backref" href="#id8">R532</a></span></dt>
<dd><p>Johnson, C. R. “Positive Definite Matrices.” Amer.
Math. Monthly 77, 259-264 1970.</p>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.is_negative_definite">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_negative_definite</span></span><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.is_negative_definite" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds out the definiteness of a matrix.</p>
<p class="rubric">Explanation</p>
<p>A square real matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \geq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(x^T A x &lt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \leq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero real vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(x^T A x &gt; 0 &gt; y^T A y\)</span>.</p></li>
</ul>
<p>A square complex matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \geq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &lt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \leq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero complex vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0 &gt; \text{re}(y^H A y)\)</span>.</p></li>
</ul>
<p>A matrix need not be symmetric or hermitian to be positive definite.</p>
<ul class="simple">
<li><p>A real non-symmetric matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> is positive definite.</p></li>
<li><p>A complex non-hermitian matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span> is positive definite.</p></li>
</ul>
<p>And this extension can apply for all the definitions above.</p>
<p>However, for complex cases, you can restrict the definition of
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span> to <span class="math notranslate nohighlight">\(x^H A x &gt; 0\)</span> and require the matrix
to be hermitian.
But we do not present this restriction for computation because you
can check <code class="docutils literal notranslate"><span class="pre">M.is_hermitian</span></code> independently with this and use
the same procedure.</p>
<p class="rubric">Examples</p>
<p>An example of symmetric positive definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.plotting</span> <span class="kn">import</span> <span class="n">plot3d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-6.png">png</a>, <a class="reference external" href="matrices-6.hires.png">hires.png</a>, <a class="reference external" href="matrices-6.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-6.png" class="plot-directive" src="../../_images/matrices-6.png" />
</figure>
<p>An example of symmetric positive semidefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-7.png">png</a>, <a class="reference external" href="matrices-7.hires.png">hires.png</a>, <a class="reference external" href="matrices-7.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-7.png" class="plot-directive" src="../../_images/matrices-7.png" />
</figure>
<p>An example of symmetric negative definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_semidefinite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-8.png">png</a>, <a class="reference external" href="matrices-8.hires.png">hires.png</a>, <a class="reference external" href="matrices-8.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-8.png" class="plot-directive" src="../../_images/matrices-8.png" />
</figure>
<p>An example of symmetric indefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-9.png">png</a>, <a class="reference external" href="matrices-9.hires.png">hires.png</a>, <a class="reference external" href="matrices-9.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-9.png" class="plot-directive" src="../../_images/matrices-9.png" />
</figure>
<p>An example of non-symmetric positive definite matrix.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-10.png">png</a>, <a class="reference external" href="matrices-10.hires.png">hires.png</a>, <a class="reference external" href="matrices-10.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-10.png" class="plot-directive" src="../../_images/matrices-10.png" />
</figure>
<p class="rubric">Notes</p>
<p>Although some people trivialize the definition of positive definite
matrices only for symmetric or hermitian matrices, this restriction
is not correct because it does not classify all instances of
positive definite matrices from the definition <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span> or
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>.</p>
<p>For instance, <code class="docutils literal notranslate"><span class="pre">Matrix([[1,</span> <span class="pre">2],</span> <span class="pre">[-2,</span> <span class="pre">1]])</span></code> presented in
the example above is an example of real positive definite matrix
that is not symmetric.</p>
<p>However, since the following formula holds true;</p>
<div class="math notranslate nohighlight">
\[\text{re}(x^H A x) &gt; 0 \iff
\text{re}(x^H \frac{A + A^H}{2} x) &gt; 0\]</div>
<p>We can classify all positive definite matrices that may or may not
be symmetric or hermitian by transforming the matrix to
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> or <span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span>
(which is guaranteed to be always real symmetric or complex
hermitian) and we can defer most of the studies to symmetric or
hermitian positive definite matrices.</p>
<p>But it is a different problem for the existance of Cholesky
decomposition. Because even though a non symmetric or a non
hermitian matrix can be positive definite, Cholesky or LDL
decomposition does not exist because the decompositions require the
matrix to be symmetric or hermitian.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r533"><span class="brackets"><a class="fn-backref" href="#id9">R533</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues">https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues</a></p>
</dd>
<dt class="label" id="r534"><span class="brackets"><a class="fn-backref" href="#id10">R534</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/PositiveDefiniteMatrix.html">http://mathworld.wolfram.com/PositiveDefiniteMatrix.html</a></p>
</dd>
<dt class="label" id="r535"><span class="brackets"><a class="fn-backref" href="#id11">R535</a></span></dt>
<dd><p>Johnson, C. R. “Positive Definite Matrices.” Amer.
Math. Monthly 77, 259-264 1970.</p>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.is_negative_semidefinite">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_negative_semidefinite</span></span><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.is_negative_semidefinite" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds out the definiteness of a matrix.</p>
<p class="rubric">Explanation</p>
<p>A square real matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \geq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(x^T A x &lt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \leq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero real vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(x^T A x &gt; 0 &gt; y^T A y\)</span>.</p></li>
</ul>
<p>A square complex matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \geq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &lt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \leq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero complex vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0 &gt; \text{re}(y^H A y)\)</span>.</p></li>
</ul>
<p>A matrix need not be symmetric or hermitian to be positive definite.</p>
<ul class="simple">
<li><p>A real non-symmetric matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> is positive definite.</p></li>
<li><p>A complex non-hermitian matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span> is positive definite.</p></li>
</ul>
<p>And this extension can apply for all the definitions above.</p>
<p>However, for complex cases, you can restrict the definition of
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span> to <span class="math notranslate nohighlight">\(x^H A x &gt; 0\)</span> and require the matrix
to be hermitian.
But we do not present this restriction for computation because you
can check <code class="docutils literal notranslate"><span class="pre">M.is_hermitian</span></code> independently with this and use
the same procedure.</p>
<p class="rubric">Examples</p>
<p>An example of symmetric positive definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.plotting</span> <span class="kn">import</span> <span class="n">plot3d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-11.png">png</a>, <a class="reference external" href="matrices-11.hires.png">hires.png</a>, <a class="reference external" href="matrices-11.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-11.png" class="plot-directive" src="../../_images/matrices-11.png" />
</figure>
<p>An example of symmetric positive semidefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-12.png">png</a>, <a class="reference external" href="matrices-12.hires.png">hires.png</a>, <a class="reference external" href="matrices-12.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-12.png" class="plot-directive" src="../../_images/matrices-12.png" />
</figure>
<p>An example of symmetric negative definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_semidefinite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-13.png">png</a>, <a class="reference external" href="matrices-13.hires.png">hires.png</a>, <a class="reference external" href="matrices-13.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-13.png" class="plot-directive" src="../../_images/matrices-13.png" />
</figure>
<p>An example of symmetric indefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-14.png">png</a>, <a class="reference external" href="matrices-14.hires.png">hires.png</a>, <a class="reference external" href="matrices-14.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-14.png" class="plot-directive" src="../../_images/matrices-14.png" />
</figure>
<p>An example of non-symmetric positive definite matrix.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-15.png">png</a>, <a class="reference external" href="matrices-15.hires.png">hires.png</a>, <a class="reference external" href="matrices-15.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-15.png" class="plot-directive" src="../../_images/matrices-15.png" />
</figure>
<p class="rubric">Notes</p>
<p>Although some people trivialize the definition of positive definite
matrices only for symmetric or hermitian matrices, this restriction
is not correct because it does not classify all instances of
positive definite matrices from the definition <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span> or
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>.</p>
<p>For instance, <code class="docutils literal notranslate"><span class="pre">Matrix([[1,</span> <span class="pre">2],</span> <span class="pre">[-2,</span> <span class="pre">1]])</span></code> presented in
the example above is an example of real positive definite matrix
that is not symmetric.</p>
<p>However, since the following formula holds true;</p>
<div class="math notranslate nohighlight">
\[\text{re}(x^H A x) &gt; 0 \iff
\text{re}(x^H \frac{A + A^H}{2} x) &gt; 0\]</div>
<p>We can classify all positive definite matrices that may or may not
be symmetric or hermitian by transforming the matrix to
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> or <span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span>
(which is guaranteed to be always real symmetric or complex
hermitian) and we can defer most of the studies to symmetric or
hermitian positive definite matrices.</p>
<p>But it is a different problem for the existance of Cholesky
decomposition. Because even though a non symmetric or a non
hermitian matrix can be positive definite, Cholesky or LDL
decomposition does not exist because the decompositions require the
matrix to be symmetric or hermitian.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r536"><span class="brackets"><a class="fn-backref" href="#id12">R536</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues">https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues</a></p>
</dd>
<dt class="label" id="r537"><span class="brackets"><a class="fn-backref" href="#id13">R537</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/PositiveDefiniteMatrix.html">http://mathworld.wolfram.com/PositiveDefiniteMatrix.html</a></p>
</dd>
<dt class="label" id="r538"><span class="brackets"><a class="fn-backref" href="#id14">R538</a></span></dt>
<dd><p>Johnson, C. R. “Positive Definite Matrices.” Amer.
Math. Monthly 77, 259-264 1970.</p>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.is_positive_definite">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_positive_definite</span></span><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.is_positive_definite" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds out the definiteness of a matrix.</p>
<p class="rubric">Explanation</p>
<p>A square real matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \geq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(x^T A x &lt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \leq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero real vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(x^T A x &gt; 0 &gt; y^T A y\)</span>.</p></li>
</ul>
<p>A square complex matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \geq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &lt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \leq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero complex vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0 &gt; \text{re}(y^H A y)\)</span>.</p></li>
</ul>
<p>A matrix need not be symmetric or hermitian to be positive definite.</p>
<ul class="simple">
<li><p>A real non-symmetric matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> is positive definite.</p></li>
<li><p>A complex non-hermitian matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span> is positive definite.</p></li>
</ul>
<p>And this extension can apply for all the definitions above.</p>
<p>However, for complex cases, you can restrict the definition of
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span> to <span class="math notranslate nohighlight">\(x^H A x &gt; 0\)</span> and require the matrix
to be hermitian.
But we do not present this restriction for computation because you
can check <code class="docutils literal notranslate"><span class="pre">M.is_hermitian</span></code> independently with this and use
the same procedure.</p>
<p class="rubric">Examples</p>
<p>An example of symmetric positive definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.plotting</span> <span class="kn">import</span> <span class="n">plot3d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-16.png">png</a>, <a class="reference external" href="matrices-16.hires.png">hires.png</a>, <a class="reference external" href="matrices-16.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-16.png" class="plot-directive" src="../../_images/matrices-16.png" />
</figure>
<p>An example of symmetric positive semidefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-17.png">png</a>, <a class="reference external" href="matrices-17.hires.png">hires.png</a>, <a class="reference external" href="matrices-17.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-17.png" class="plot-directive" src="../../_images/matrices-17.png" />
</figure>
<p>An example of symmetric negative definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_semidefinite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-18.png">png</a>, <a class="reference external" href="matrices-18.hires.png">hires.png</a>, <a class="reference external" href="matrices-18.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-18.png" class="plot-directive" src="../../_images/matrices-18.png" />
</figure>
<p>An example of symmetric indefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-19.png">png</a>, <a class="reference external" href="matrices-19.hires.png">hires.png</a>, <a class="reference external" href="matrices-19.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-19.png" class="plot-directive" src="../../_images/matrices-19.png" />
</figure>
<p>An example of non-symmetric positive definite matrix.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-20.png">png</a>, <a class="reference external" href="matrices-20.hires.png">hires.png</a>, <a class="reference external" href="matrices-20.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-20.png" class="plot-directive" src="../../_images/matrices-20.png" />
</figure>
<p class="rubric">Notes</p>
<p>Although some people trivialize the definition of positive definite
matrices only for symmetric or hermitian matrices, this restriction
is not correct because it does not classify all instances of
positive definite matrices from the definition <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span> or
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>.</p>
<p>For instance, <code class="docutils literal notranslate"><span class="pre">Matrix([[1,</span> <span class="pre">2],</span> <span class="pre">[-2,</span> <span class="pre">1]])</span></code> presented in
the example above is an example of real positive definite matrix
that is not symmetric.</p>
<p>However, since the following formula holds true;</p>
<div class="math notranslate nohighlight">
\[\text{re}(x^H A x) &gt; 0 \iff
\text{re}(x^H \frac{A + A^H}{2} x) &gt; 0\]</div>
<p>We can classify all positive definite matrices that may or may not
be symmetric or hermitian by transforming the matrix to
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> or <span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span>
(which is guaranteed to be always real symmetric or complex
hermitian) and we can defer most of the studies to symmetric or
hermitian positive definite matrices.</p>
<p>But it is a different problem for the existance of Cholesky
decomposition. Because even though a non symmetric or a non
hermitian matrix can be positive definite, Cholesky or LDL
decomposition does not exist because the decompositions require the
matrix to be symmetric or hermitian.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r539"><span class="brackets"><a class="fn-backref" href="#id15">R539</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues">https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues</a></p>
</dd>
<dt class="label" id="r540"><span class="brackets"><a class="fn-backref" href="#id16">R540</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/PositiveDefiniteMatrix.html">http://mathworld.wolfram.com/PositiveDefiniteMatrix.html</a></p>
</dd>
<dt class="label" id="r541"><span class="brackets"><a class="fn-backref" href="#id17">R541</a></span></dt>
<dd><p>Johnson, C. R. “Positive Definite Matrices.” Amer.
Math. Monthly 77, 259-264 1970.</p>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.is_positive_semidefinite">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_positive_semidefinite</span></span><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.is_positive_semidefinite" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds out the definiteness of a matrix.</p>
<p class="rubric">Explanation</p>
<p>A square real matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \geq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(x^T A x &lt; 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(x^T A x \leq 0\)</span>
for all non-zero real vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero real vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(x^T A x &gt; 0 &gt; y^T A y\)</span>.</p></li>
</ul>
<p>A square complex matrix <span class="math notranslate nohighlight">\(A\)</span> is:</p>
<ul class="simple">
<li><p>A positive definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A positive semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \geq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative definite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &lt; 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>A negative semidefinite matrix if <span class="math notranslate nohighlight">\(\text{re}(x^H A x) \leq 0\)</span>
for all non-zero complex vectors <span class="math notranslate nohighlight">\(x\)</span>.</p></li>
<li><p>An indefinite matrix if there exists non-zero complex vectors
<span class="math notranslate nohighlight">\(x, y\)</span> with <span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0 &gt; \text{re}(y^H A y)\)</span>.</p></li>
</ul>
<p>A matrix need not be symmetric or hermitian to be positive definite.</p>
<ul class="simple">
<li><p>A real non-symmetric matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> is positive definite.</p></li>
<li><p>A complex non-hermitian matrix is positive definite if and only if
<span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span> is positive definite.</p></li>
</ul>
<p>And this extension can apply for all the definitions above.</p>
<p>However, for complex cases, you can restrict the definition of
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span> to <span class="math notranslate nohighlight">\(x^H A x &gt; 0\)</span> and require the matrix
to be hermitian.
But we do not present this restriction for computation because you
can check <code class="docutils literal notranslate"><span class="pre">M.is_hermitian</span></code> independently with this and use
the same procedure.</p>
<p class="rubric">Examples</p>
<p>An example of symmetric positive definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.plotting</span> <span class="kn">import</span> <span class="n">plot3d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-21.png">png</a>, <a class="reference external" href="matrices-21.hires.png">hires.png</a>, <a class="reference external" href="matrices-21.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-21.png" class="plot-directive" src="../../_images/matrices-21.png" />
</figure>
<p>An example of symmetric positive semidefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-22.png">png</a>, <a class="reference external" href="matrices-22.hires.png">hires.png</a>, <a class="reference external" href="matrices-22.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-22.png" class="plot-directive" src="../../_images/matrices-22.png" />
</figure>
<p>An example of symmetric negative definite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_negative_semidefinite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-23.png">png</a>, <a class="reference external" href="matrices-23.hires.png">hires.png</a>, <a class="reference external" href="matrices-23.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-23.png" class="plot-directive" src="../../_images/matrices-23.png" />
</figure>
<p>An example of symmetric indefinite matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_indefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-24.png">png</a>, <a class="reference external" href="matrices-24.hires.png">hires.png</a>, <a class="reference external" href="matrices-24.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-24.png" class="plot-directive" src="../../_images/matrices-24.png" />
</figure>
<p>An example of non-symmetric positive definite matrix.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_definite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">is_positive_semidefinite</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">plot3d</span><span class="p">((</span><span class="n">x</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="matrices-25.png">png</a>, <a class="reference external" href="matrices-25.hires.png">hires.png</a>, <a class="reference external" href="matrices-25.pdf">pdf</a>)</p>
<figure class="align-default">
<img alt="../../_images/matrices-25.png" class="plot-directive" src="../../_images/matrices-25.png" />
</figure>
<p class="rubric">Notes</p>
<p>Although some people trivialize the definition of positive definite
matrices only for symmetric or hermitian matrices, this restriction
is not correct because it does not classify all instances of
positive definite matrices from the definition <span class="math notranslate nohighlight">\(x^T A x &gt; 0\)</span> or
<span class="math notranslate nohighlight">\(\text{re}(x^H A x) &gt; 0\)</span>.</p>
<p>For instance, <code class="docutils literal notranslate"><span class="pre">Matrix([[1,</span> <span class="pre">2],</span> <span class="pre">[-2,</span> <span class="pre">1]])</span></code> presented in
the example above is an example of real positive definite matrix
that is not symmetric.</p>
<p>However, since the following formula holds true;</p>
<div class="math notranslate nohighlight">
\[\text{re}(x^H A x) &gt; 0 \iff
\text{re}(x^H \frac{A + A^H}{2} x) &gt; 0\]</div>
<p>We can classify all positive definite matrices that may or may not
be symmetric or hermitian by transforming the matrix to
<span class="math notranslate nohighlight">\(\frac{A + A^T}{2}\)</span> or <span class="math notranslate nohighlight">\(\frac{A + A^H}{2}\)</span>
(which is guaranteed to be always real symmetric or complex
hermitian) and we can defer most of the studies to symmetric or
hermitian positive definite matrices.</p>
<p>But it is a different problem for the existance of Cholesky
decomposition. Because even though a non symmetric or a non
hermitian matrix can be positive definite, Cholesky or LDL
decomposition does not exist because the decompositions require the
matrix to be symmetric or hermitian.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r542"><span class="brackets"><a class="fn-backref" href="#id18">R542</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues">https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues</a></p>
</dd>
<dt class="label" id="r543"><span class="brackets"><a class="fn-backref" href="#id19">R543</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/PositiveDefiniteMatrix.html">http://mathworld.wolfram.com/PositiveDefiniteMatrix.html</a></p>
</dd>
<dt class="label" id="r544"><span class="brackets"><a class="fn-backref" href="#id20">R544</a></span></dt>
<dd><p>Johnson, C. R. “Positive Definite Matrices.” Amer.
Math. Monthly 77, 259-264 1970.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.jordan_form">
<span class="sig-name descname"><span class="pre">jordan_form</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">calc_transform</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L415-L416"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.jordan_form" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <span class="math notranslate nohighlight">\((P, J)\)</span> where <span class="math notranslate nohighlight">\(J\)</span> is a Jordan block
matrix and <span class="math notranslate nohighlight">\(P\)</span> is a matrix such that <span class="math notranslate nohighlight">\(M = P J P^{-1}\)</span></p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>calc_transform</strong> : bool</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">False</span></code>, then only <span class="math notranslate nohighlight">\(J\)</span> is returned.</p>
</div></blockquote>
<p><strong>chop</strong> : bool</p>
<blockquote>
<div><p>All matrices are converted to exact types when computing
eigenvalues and eigenvectors.  As a result, there may be
approximation errors.  If <code class="docutils literal notranslate"><span class="pre">chop==True</span></code>, these errors
will be truncated.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span> <span class="mi">6</span><span class="p">,</span>  <span class="mi">5</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span>  <span class="mi">3</span><span class="p">,</span>  <span class="mi">3</span><span class="p">],</span> <span class="p">[</span> <span class="mi">2</span><span class="p">,</span>  <span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span>  <span class="mi">1</span><span class="p">,</span>  <span class="mi">5</span><span class="p">,</span>  <span class="mi">5</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">,</span> <span class="n">J</span> <span class="o">=</span> <span class="n">M</span><span class="o">.</span><span class="n">jordan_form</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">J</span>
<span class="go">Matrix([</span>
<span class="go">[2, 1, 0, 0],</span>
<span class="go">[0, 2, 0, 0],</span>
<span class="go">[0, 0, 2, 1],</span>
<span class="go">[0, 0, 0, 2]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.jordan_block" title="sympy.matrices.common.MatrixCommon.jordan_block"><code class="xref py py-obj docutils literal notranslate"><span class="pre">jordan_block</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.left_eigenvects">
<span class="sig-name descname"><span class="pre">left_eigenvects</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">flags</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L418-L419"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.left_eigenvects" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns left eigenvectors and eigenvalues.</p>
<p>This function returns the list of triples (eigenval, multiplicity,
basis) for the left eigenvectors. Options are the same as for
eigenvects(), i.e. the <code class="docutils literal notranslate"><span class="pre">**flags</span></code> arguments gets passed directly to
eigenvects().</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">eigenvects</span><span class="p">()</span>
<span class="go">[(-1, 1, [Matrix([</span>
<span class="go">[-1],</span>
<span class="go">[ 1],</span>
<span class="go">[ 0]])]), (0, 1, [Matrix([</span>
<span class="go">[ 0],</span>
<span class="go">[-1],</span>
<span class="go">[ 1]])]), (2, 1, [Matrix([</span>
<span class="go">[2/3],</span>
<span class="go">[1/3],</span>
<span class="go">[  1]])])]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">left_eigenvects</span><span class="p">()</span>
<span class="go">[(-1, 1, [Matrix([[-2, 1, 1]])]), (0, 1, [Matrix([[-1, -1, 1]])]), (2,</span>
<span class="go">1, [Matrix([[1, 1, 1]])])]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixEigen.singular_values">
<span class="sig-name descname"><span class="pre">singular_values</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L421-L422"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixEigen.singular_values" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the singular values of a Matrix</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">singular_values</span><span class="p">()</span>
<span class="go">[sqrt(x**2 + 1), 1, 0]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.condition_number" title="sympy.matrices.matrices.MatrixBase.condition_number"><code class="xref py py-obj docutils literal notranslate"><span class="pre">condition_number</span></code></a></p>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="matrixcalculus-class-reference">
<h2>MatrixCalculus Class Reference<a class="headerlink" href="#matrixcalculus-class-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixCalculus">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">MatrixCalculus</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L440-L581"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixCalculus" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides calculus-related matrix operations.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixCalculus.diff">
<span class="sig-name descname"><span class="pre">diff</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L443-L471"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixCalculus.diff" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate the derivative of each element in the matrix.
<code class="docutils literal notranslate"><span class="pre">args</span></code> will be passed to the <code class="docutils literal notranslate"><span class="pre">integrate</span></code> function.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0],</span>
<span class="go">[0, 0]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixCalculus.integrate" title="sympy.matrices.matrices.MatrixCalculus.integrate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">integrate</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixCalculus.limit" title="sympy.matrices.matrices.MatrixCalculus.limit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">limit</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixCalculus.integrate">
<span class="sig-name descname"><span class="pre">integrate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L476-L501"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixCalculus.integrate" title="Permalink to this definition">¶</a></dt>
<dd><p>Integrate each element of the matrix.  <code class="docutils literal notranslate"><span class="pre">args</span></code> will
be passed to the <code class="docutils literal notranslate"><span class="pre">integrate</span></code> function.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">integrate</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="p">))</span>
<span class="go">Matrix([</span>
<span class="go">[x**2/2, x*y],</span>
<span class="go">[     x,   0]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">integrate</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">Matrix([</span>
<span class="go">[2, 2*y],</span>
<span class="go">[2,   0]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixCalculus.limit" title="sympy.matrices.matrices.MatrixCalculus.limit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">limit</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixCalculus.diff" title="sympy.matrices.matrices.MatrixCalculus.diff"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diff</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixCalculus.jacobian">
<span class="sig-name descname"><span class="pre">jacobian</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L503-L558"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixCalculus.jacobian" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the Jacobian matrix (derivative of a vector-valued function).</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>``self``</strong> : vector of expressions representing functions f_i(x_1, …, x_n).</p>
<p><strong>X</strong> : set of x_i’s in order, it can be a list or a Matrix</p>
<p><strong>Both ``self`` and X can be a row or a column matrix in any order</strong></p>
<p><strong>(i.e., jacobian() should always work).</strong></p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">rho</span><span class="p">,</span> <span class="n">phi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">rho</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">),</span> <span class="n">rho</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">),</span> <span class="n">rho</span><span class="o">**</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">rho</span><span class="p">,</span> <span class="n">phi</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">jacobian</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[cos(phi), -rho*sin(phi)],</span>
<span class="go">[sin(phi),  rho*cos(phi)],</span>
<span class="go">[   2*rho,             0]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">rho</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">),</span> <span class="n">rho</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">jacobian</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[cos(phi), -rho*sin(phi)],</span>
<span class="go">[sin(phi),  rho*cos(phi)]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.dense.hessian" title="sympy.matrices.dense.hessian"><code class="xref py py-obj docutils literal notranslate"><span class="pre">hessian</span></code></a>, <a class="reference internal" href="#sympy.matrices.dense.wronskian" title="sympy.matrices.dense.wronskian"><code class="xref py py-obj docutils literal notranslate"><span class="pre">wronskian</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixCalculus.limit">
<span class="sig-name descname"><span class="pre">limit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L560-L581"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixCalculus.limit" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate the limit of each element in the matrix.
<code class="docutils literal notranslate"><span class="pre">args</span></code> will be passed to the <code class="docutils literal notranslate"><span class="pre">limit</span></code> function.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">limit</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[2, y],</span>
<span class="go">[1, 0]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixCalculus.integrate" title="sympy.matrices.matrices.MatrixCalculus.integrate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">integrate</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixCalculus.diff" title="sympy.matrices.matrices.MatrixCalculus.diff"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diff</span></code></a></p>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="matrixbase-class-reference">
<h2>MatrixBase Class Reference<a class="headerlink" href="#matrixbase-class-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">MatrixBase</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L776-L2279"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for matrix objects.</p>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.D">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">D</span></span><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.D" title="Permalink to this definition">¶</a></dt>
<dd><p>Return Dirac conjugate (if <code class="docutils literal notranslate"><span class="pre">self.rows</span> <span class="pre">==</span> <span class="pre">4</span></code>).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">I</span><span class="p">,</span> <span class="n">eye</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">I</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">D</span>
<span class="go">Matrix([[0, 1 - I, -2, -3]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="p">(</span><span class="n">eye</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">eye</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">D</span>
<span class="go">Matrix([</span>
<span class="go">[1 - I,     0,      0,      0],</span>
<span class="go">[    0, 1 - I,      0,      0],</span>
<span class="go">[    0,     0, -1 + I,      0],</span>
<span class="go">[    2,     0,      0, -1 + I]])</span>
</pre></div>
</div>
<p>If the matrix does not have 4 rows an AttributeError will be raised
because this property is only defined for matrices with 4 rows.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">(</span><span class="n">eye</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">D</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">AttributeError</span>: <span class="n">Matrix has no attribute D.</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.conjugate" title="sympy.matrices.common.MatrixCommon.conjugate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.common.MatrixCommon.conjugate</span></code></a></dt><dd><p>By-element conjugation</p>
</dd>
<dt><a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.H" title="sympy.matrices.common.MatrixCommon.H"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.common.MatrixCommon.H</span></code></a></dt><dd><p>Hermite conjugation</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.LDLdecomposition">
<span class="sig-name descname"><span class="pre">LDLdecomposition</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">hermitian</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2137-L2138"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.LDLdecomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the LDL Decomposition (L, D) of matrix A,
such that L * D * L.H == A if hermitian flag is True, or
L * D * L.T == A if hermitian is False.
This method eliminates the use of square root.
Further this ensures that all the diagonal entries of L are 1.
A must be a Hermitian positive-definite matrix if hermitian is True,
or a symmetric matrix otherwise.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">eye</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(((</span><span class="mi">25</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="o">-</span><span class="mi">5</span><span class="p">),</span> <span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="mi">18</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">11</span><span class="p">)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span><span class="p">,</span> <span class="n">D</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">LDLdecomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span>
<span class="go">Matrix([</span>
<span class="go">[   1,   0, 0],</span>
<span class="go">[ 3/5,   1, 0],</span>
<span class="go">[-1/5, 1/3, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span>
<span class="go">Matrix([</span>
<span class="go">[25, 0, 0],</span>
<span class="go">[ 0, 9, 0],</span>
<span class="go">[ 0, 0, 9]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span> <span class="o">*</span> <span class="n">D</span> <span class="o">*</span> <span class="n">L</span><span class="o">.</span><span class="n">T</span> <span class="o">*</span> <span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">()</span> <span class="o">==</span> <span class="n">eye</span><span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">rows</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>The matrix can have complex entries:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(((</span><span class="mi">9</span><span class="p">,</span> <span class="mi">3</span><span class="o">*</span><span class="n">I</span><span class="p">),</span> <span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="o">*</span><span class="n">I</span><span class="p">,</span> <span class="mi">5</span><span class="p">)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span><span class="p">,</span> <span class="n">D</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">LDLdecomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span>
<span class="go">Matrix([</span>
<span class="go">[   1, 0],</span>
<span class="go">[-I/3, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span>
<span class="go">Matrix([</span>
<span class="go">[9, 0],</span>
<span class="go">[0, 4]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span><span class="o">*</span><span class="n">D</span><span class="o">*</span><span class="n">L</span><span class="o">.</span><span class="n">H</span> <span class="o">==</span> <span class="n">A</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.cholesky" title="sympy.matrices.dense.DenseMatrix.cholesky"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.cholesky</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition" title="sympy.matrices.matrices.MatrixBase.LUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixBase.LUdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRdecomposition" title="sympy.matrices.matrices.MatrixBase.QRdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRdecomposition</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.LDLsolve">
<span class="sig-name descname"><span class="pre">LDLsolve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2174-L2175"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.LDLsolve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solves <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">B</span></code> using LDL decomposition,
for a general square and non-singular matrix.</p>
<p>For a non-square matrix with rows &gt; cols,
the least squares solution is returned.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">eye</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">eye</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">LDLsolve</span><span class="p">(</span><span class="n">B</span><span class="p">)</span> <span class="o">==</span> <span class="n">B</span><span class="o">/</span><span class="mi">2</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.LDLdecomposition" title="sympy.matrices.dense.DenseMatrix.LDLdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.LDLdecomposition</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.lower_triangular_solve" title="sympy.matrices.dense.DenseMatrix.lower_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.lower_triangular_solve</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.upper_triangular_solve" title="sympy.matrices.dense.DenseMatrix.upper_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.upper_triangular_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.gauss_jordan_solve" title="sympy.matrices.matrices.MatrixBase.gauss_jordan_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">gauss_jordan_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.cholesky_solve" title="sympy.matrices.matrices.MatrixBase.cholesky_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cholesky_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.diagonal_solve" title="sympy.matrices.matrices.MatrixBase.diagonal_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonal_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="sympy.matrices.matrices.MatrixBase.QRsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv_solve" title="sympy.matrices.matrices.MatrixBase.pinv_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv_solve</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.LUdecomposition">
<span class="sig-name descname"><span class="pre">LUdecomposition</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em>, <em class="sig-param"><span class="pre">simpfunc=None</span></em>, <em class="sig-param"><span class="pre">rankcheck=False</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2140-L2143"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns (L, U, perm) where L is a lower triangular matrix with unit
diagonal, U is an upper triangular matrix, and perm is a list of row
swap index pairs. If A is the original matrix, then
<code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">=</span> <span class="pre">(L*U).permuteBkwd(perm)</span></code>, and the row permutation matrix P such
that <span class="math notranslate nohighlight">\(P A = L U\)</span> can be computed by <code class="docutils literal notranslate"><span class="pre">P</span> <span class="pre">=</span> <span class="pre">eye(A.rows).permuteFwd(perm)</span></code>.</p>
<p>See documentation for LUCombined for details about the keyword argument
rankcheck, iszerofunc, and simpfunc.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rankcheck</strong> : bool, optional</p>
<blockquote>
<div><p>Determines if this function should detect the rank
deficiency of the matrixis and should raise a
<code class="docutils literal notranslate"><span class="pre">ValueError</span></code>.</p>
</div></blockquote>
<p><strong>iszerofunc</strong> : function, optional</p>
<blockquote>
<div><p>A function which determines if a given expression is zero.</p>
<p>The function should be a callable that takes a single
sympy expression and returns a 3-valued boolean value
<code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="docutils literal notranslate"><span class="pre">False</span></code>, or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<p>It is internally used by the pivot searching algorithm.
See the notes section for a more information about the
pivot searching algorithm.</p>
</div></blockquote>
<p><strong>simpfunc</strong> : function or None, optional</p>
<blockquote>
<div><p>A function that simplifies the input.</p>
<p>If this is specified as a function, this function should be
a callable that takes a single sympy expression and returns
an another sympy expression that is algebraically
equivalent.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">None</span></code>, it indicates that the pivot search algorithm
should not attempt to simplify any candidate pivots.</p>
<p>It is internally used by the pivot searching algorithm.
See the notes section for a more information about the
pivot searching algorithm.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">6</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span><span class="p">,</span> <span class="n">U</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">LUdecomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span>
<span class="go">Matrix([</span>
<span class="go">[  1, 0],</span>
<span class="go">[3/2, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U</span>
<span class="go">Matrix([</span>
<span class="go">[4,    3],</span>
<span class="go">[0, -3/2]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.cholesky" title="sympy.matrices.dense.DenseMatrix.cholesky"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.cholesky</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.LDLdecomposition" title="sympy.matrices.dense.DenseMatrix.LDLdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.LDLdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRdecomposition" title="sympy.matrices.matrices.MatrixBase.QRdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition_Simple" title="sympy.matrices.matrices.MatrixBase.LUdecomposition_Simple"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUdecomposition_Simple</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecompositionFF" title="sympy.matrices.matrices.MatrixBase.LUdecompositionFF"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUdecompositionFF</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.LUdecompositionFF">
<span class="sig-name descname"><span class="pre">LUdecompositionFF</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2150-L2151"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.LUdecompositionFF" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute a fraction-free LU decomposition.</p>
<p>Returns 4 matrices P, L, D, U such that PA = L D**-1 U.
If the elements of the matrix belong to some integral domain I, then all
elements of L, D and U are guaranteed to belong to I.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition" title="sympy.matrices.matrices.MatrixBase.LUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixBase.LUdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition_Simple" title="sympy.matrices.matrices.MatrixBase.LUdecomposition_Simple"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUdecomposition_Simple</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r545"><span class="brackets"><a class="fn-backref" href="#id21">R545</a></span></dt>
<dd><p>W. Zhou &amp; D.J. Jeffrey, “Fraction-free matrix factors: new forms
for LU and QR factors”. Frontiers in Computer Science in China,
Vol 2, no. 1, pp. 67-80, 2008.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.LUdecomposition_Simple">
<span class="sig-name descname"><span class="pre">LUdecomposition_Simple</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em>, <em class="sig-param"><span class="pre">simpfunc=None</span></em>, <em class="sig-param"><span class="pre">rankcheck=False</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2145-L2148"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition_Simple" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the PLU decomposition of the matrix.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rankcheck</strong> : bool, optional</p>
<blockquote>
<div><p>Determines if this function should detect the rank
deficiency of the matrixis and should raise a
<code class="docutils literal notranslate"><span class="pre">ValueError</span></code>.</p>
</div></blockquote>
<p><strong>iszerofunc</strong> : function, optional</p>
<blockquote>
<div><p>A function which determines if a given expression is zero.</p>
<p>The function should be a callable that takes a single
sympy expression and returns a 3-valued boolean value
<code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="docutils literal notranslate"><span class="pre">False</span></code>, or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<p>It is internally used by the pivot searching algorithm.
See the notes section for a more information about the
pivot searching algorithm.</p>
</div></blockquote>
<p><strong>simpfunc</strong> : function or None, optional</p>
<blockquote>
<div><p>A function that simplifies the input.</p>
<p>If this is specified as a function, this function should be
a callable that takes a single sympy expression and returns
an another sympy expression that is algebraically
equivalent.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">None</span></code>, it indicates that the pivot search algorithm
should not attempt to simplify any candidate pivots.</p>
<p>It is internally used by the pivot searching algorithm.
See the notes section for a more information about the
pivot searching algorithm.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>(lu, row_swaps)</strong> : (Matrix, list)</p>
<blockquote>
<div><p>If the original matrix is a <span class="math notranslate nohighlight">\(m, n\)</span> matrix:</p>
<p><em>lu</em> is a <span class="math notranslate nohighlight">\(m, n\)</span> matrix, which contains result of the
decomposition in a compresed form. See the notes section
to see how the matrix is compressed.</p>
<p><em>row_swaps</em> is a <span class="math notranslate nohighlight">\(m\)</span>-element list where each element is a
pair of row exchange indices.</p>
<p><code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">=</span> <span class="pre">(L*U).permute_backward(perm)</span></code>, and the row
permutation matrix <span class="math notranslate nohighlight">\(P\)</span> from the formula <span class="math notranslate nohighlight">\(P A = L U\)</span> can be
computed by <code class="docutils literal notranslate"><span class="pre">P=eye(A.row).permute_forward(perm)</span></code>.</p>
</div></blockquote>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><strong>ValueError</strong></p>
<blockquote>
<div><p>Raised if <code class="docutils literal notranslate"><span class="pre">rankcheck=True</span></code> and the matrix is found to
be rank deficient during the computation.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>About the PLU decomposition:</p>
<p>PLU decomposition is a generalization of a LU decomposition
which can be extended for rank-deficient matrices.</p>
<p>It can further be generalized for non-square matrices, and this
is the notation that SymPy is using.</p>
<p>PLU decomposition is a decomposition of a <span class="math notranslate nohighlight">\(m, n\)</span> matrix <span class="math notranslate nohighlight">\(A\)</span> in
the form of <span class="math notranslate nohighlight">\(P A = L U\)</span> where</p>
<ul class="simple">
<li><dl class="simple">
<dt><span class="math notranslate nohighlight">\(L\)</span> is a <span class="math notranslate nohighlight">\(m, m\)</span> lower triangular matrix with unit diagonal</dt><dd><p>entries.</p>
</dd>
</dl>
</li>
<li><p><span class="math notranslate nohighlight">\(U\)</span> is a <span class="math notranslate nohighlight">\(m, n\)</span> upper triangular matrix.</p></li>
<li><p><span class="math notranslate nohighlight">\(P\)</span> is a <span class="math notranslate nohighlight">\(m, m\)</span> permutation matrix.</p></li>
</ul>
<p>So, for a square matrix, the decomposition would look like:</p>
<div class="math notranslate nohighlight">
\[\begin{split}L = \begin{bmatrix}
1 &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\
L_{1, 0} &amp; 1 &amp; 0 &amp; \cdots &amp; 0 \\
L_{2, 0} &amp; L_{2, 1} &amp; 1 &amp; \cdots &amp; 0 \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots \\
L_{n-1, 0} &amp; L_{n-1, 1} &amp; L_{n-1, 2} &amp; \cdots &amp; 1
\end{bmatrix}\end{split}\]</div>
<div class="math notranslate nohighlight">
\[\begin{split}U = \begin{bmatrix}
U_{0, 0} &amp; U_{0, 1} &amp; U_{0, 2} &amp; \cdots &amp; U_{0, n-1} \\
0 &amp; U_{1, 1} &amp; U_{1, 2} &amp; \cdots &amp; U_{1, n-1} \\
0 &amp; 0 &amp; U_{2, 2} &amp; \cdots &amp; U_{2, n-1} \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots \\
0 &amp; 0 &amp; 0 &amp; \cdots &amp; U_{n-1, n-1}
\end{bmatrix}\end{split}\]</div>
<p>And for a matrix with more rows than the columns,
the decomposition would look like:</p>
<div class="math notranslate nohighlight">
\[\begin{split}L = \begin{bmatrix}
1 &amp; 0 &amp; 0 &amp; \cdots &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\
L_{1, 0} &amp; 1 &amp; 0 &amp; \cdots &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\
L_{2, 0} &amp; L_{2, 1} &amp; 1 &amp; \cdots &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots &amp; \vdots &amp; \ddots
&amp; \vdots \\
L_{n-1, 0} &amp; L_{n-1, 1} &amp; L_{n-1, 2} &amp; \cdots &amp; 1 &amp; 0
&amp; \cdots &amp; 0 \\
L_{n, 0} &amp; L_{n, 1} &amp; L_{n, 2} &amp; \cdots &amp; L_{n, n-1} &amp; 1
&amp; \cdots &amp; 0 \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots &amp; \vdots
&amp; \ddots &amp; \vdots \\
L_{m-1, 0} &amp; L_{m-1, 1} &amp; L_{m-1, 2} &amp; \cdots &amp; L_{m-1, n-1}
&amp; 0 &amp; \cdots &amp; 1 \\
\end{bmatrix}\end{split}\]</div>
<div class="math notranslate nohighlight">
\[\begin{split}U = \begin{bmatrix}
U_{0, 0} &amp; U_{0, 1} &amp; U_{0, 2} &amp; \cdots &amp; U_{0, n-1} \\
0 &amp; U_{1, 1} &amp; U_{1, 2} &amp; \cdots &amp; U_{1, n-1} \\
0 &amp; 0 &amp; U_{2, 2} &amp; \cdots &amp; U_{2, n-1} \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots \\
0 &amp; 0 &amp; 0 &amp; \cdots &amp; U_{n-1, n-1} \\
0 &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots \\
0 &amp; 0 &amp; 0 &amp; \cdots &amp; 0
\end{bmatrix}\end{split}\]</div>
<p>Finally, for a matrix with more columns than the rows, the
decomposition would look like:</p>
<div class="math notranslate nohighlight">
\[\begin{split}L = \begin{bmatrix}
1 &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\
L_{1, 0} &amp; 1 &amp; 0 &amp; \cdots &amp; 0 \\
L_{2, 0} &amp; L_{2, 1} &amp; 1 &amp; \cdots &amp; 0 \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots \\
L_{m-1, 0} &amp; L_{m-1, 1} &amp; L_{m-1, 2} &amp; \cdots &amp; 1
\end{bmatrix}\end{split}\]</div>
<div class="math notranslate nohighlight">
\[\begin{split}U = \begin{bmatrix}
U_{0, 0} &amp; U_{0, 1} &amp; U_{0, 2} &amp; \cdots &amp; U_{0, m-1}
&amp; \cdots &amp; U_{0, n-1} \\
0 &amp; U_{1, 1} &amp; U_{1, 2} &amp; \cdots &amp; U_{1, m-1}
&amp; \cdots &amp; U_{1, n-1} \\
0 &amp; 0 &amp; U_{2, 2} &amp; \cdots &amp; U_{2, m-1}
&amp; \cdots &amp; U_{2, n-1} \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots
&amp; \cdots &amp; \vdots \\
0 &amp; 0 &amp; 0 &amp; \cdots &amp; U_{m-1, m-1}
&amp; \cdots &amp; U_{m-1, n-1} \\
\end{bmatrix}\end{split}\]</div>
<p>About the compressed LU storage:</p>
<p>The results of the decomposition are often stored in compressed
forms rather than returning <span class="math notranslate nohighlight">\(L\)</span> and <span class="math notranslate nohighlight">\(U\)</span> matrices individually.</p>
<p>It may be less intiuitive, but it is commonly used for a lot of
numeric libraries because of the efficiency.</p>
<p>The storage matrix is defined as following for this specific
method:</p>
<ul class="simple">
<li><dl class="simple">
<dt>The subdiagonal elements of <span class="math notranslate nohighlight">\(L\)</span> are stored in the subdiagonal</dt><dd><p>portion of <span class="math notranslate nohighlight">\(LU\)</span>, that is <span class="math notranslate nohighlight">\(LU_{i, j} = L_{i, j}\)</span> whenever
<span class="math notranslate nohighlight">\(i &gt; j\)</span>.</p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>The elements on the diagonal of <span class="math notranslate nohighlight">\(L\)</span> are all 1, and are not</dt><dd><p>explicitly stored.</p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt><span class="math notranslate nohighlight">\(U\)</span> is stored in the upper triangular portion of <span class="math notranslate nohighlight">\(LU\)</span>, that is</dt><dd><p><span class="math notranslate nohighlight">\(LU_{i, j} = U_{i, j}\)</span> whenever <span class="math notranslate nohighlight">\(i &lt;= j\)</span>.</p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>For a case of <span class="math notranslate nohighlight">\(m &gt; n\)</span>, the right side of the <span class="math notranslate nohighlight">\(L\)</span> matrix is</dt><dd><p>trivial to store.</p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>For a case of <span class="math notranslate nohighlight">\(m &lt; n\)</span>, the below side of the <span class="math notranslate nohighlight">\(U\)</span> matrix is</dt><dd><p>trivial to store.</p>
</dd>
</dl>
</li>
</ul>
<p>So, for a square matrix, the compressed output matrix would be:</p>
<div class="math notranslate nohighlight">
\[\begin{split}LU = \begin{bmatrix}
U_{0, 0} &amp; U_{0, 1} &amp; U_{0, 2} &amp; \cdots &amp; U_{0, n-1} \\
L_{1, 0} &amp; U_{1, 1} &amp; U_{1, 2} &amp; \cdots &amp; U_{1, n-1} \\
L_{2, 0} &amp; L_{2, 1} &amp; U_{2, 2} &amp; \cdots &amp; U_{2, n-1} \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots \\
L_{n-1, 0} &amp; L_{n-1, 1} &amp; L_{n-1, 2} &amp; \cdots &amp; U_{n-1, n-1}
\end{bmatrix}\end{split}\]</div>
<p>For a matrix with more rows than the columns, the compressed
output matrix would be:</p>
<div class="math notranslate nohighlight">
\[\begin{split}LU = \begin{bmatrix}
U_{0, 0} &amp; U_{0, 1} &amp; U_{0, 2} &amp; \cdots &amp; U_{0, n-1} \\
L_{1, 0} &amp; U_{1, 1} &amp; U_{1, 2} &amp; \cdots &amp; U_{1, n-1} \\
L_{2, 0} &amp; L_{2, 1} &amp; U_{2, 2} &amp; \cdots &amp; U_{2, n-1} \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots \\
L_{n-1, 0} &amp; L_{n-1, 1} &amp; L_{n-1, 2} &amp; \cdots
&amp; U_{n-1, n-1} \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots \\
L_{m-1, 0} &amp; L_{m-1, 1} &amp; L_{m-1, 2} &amp; \cdots
&amp; L_{m-1, n-1} \\
\end{bmatrix}\end{split}\]</div>
<p>For a matrix with more columns than the rows, the compressed
output matrix would be:</p>
<div class="math notranslate nohighlight">
\[\begin{split}LU = \begin{bmatrix}
U_{0, 0} &amp; U_{0, 1} &amp; U_{0, 2} &amp; \cdots &amp; U_{0, m-1}
&amp; \cdots &amp; U_{0, n-1} \\
L_{1, 0} &amp; U_{1, 1} &amp; U_{1, 2} &amp; \cdots &amp; U_{1, m-1}
&amp; \cdots &amp; U_{1, n-1} \\
L_{2, 0} &amp; L_{2, 1} &amp; U_{2, 2} &amp; \cdots &amp; U_{2, m-1}
&amp; \cdots &amp; U_{2, n-1} \\
\vdots &amp; \vdots &amp; \vdots &amp; \ddots &amp; \vdots
&amp; \cdots &amp; \vdots \\
L_{m-1, 0} &amp; L_{m-1, 1} &amp; L_{m-1, 2} &amp; \cdots &amp; U_{m-1, m-1}
&amp; \cdots &amp; U_{m-1, n-1} \\
\end{bmatrix}\end{split}\]</div>
<p>About the pivot searching algorithm:</p>
<p>When a matrix contains symbolic entries, the pivot search algorithm
differs from the case where every entry can be categorized as zero or
nonzero.
The algorithm searches column by column through the submatrix whose
top left entry coincides with the pivot position.
If it exists, the pivot is the first entry in the current search
column that iszerofunc guarantees is nonzero.
If no such candidate exists, then each candidate pivot is simplified
if simpfunc is not None.
The search is repeated, with the difference that a candidate may be
the pivot if <code class="docutils literal notranslate"><span class="pre">iszerofunc()</span></code> cannot guarantee that it is nonzero.
In the second search the pivot is the first candidate that
iszerofunc can guarantee is nonzero.
If no such candidate exists, then the pivot is the first candidate
for which iszerofunc returns None.
If no such candidate exists, then the search is repeated in the next
column to the right.
The pivot search algorithm differs from the one in <code class="docutils literal notranslate"><span class="pre">rref()</span></code>, which
relies on <code class="docutils literal notranslate"><span class="pre">_find_reasonable_pivot()</span></code>.
Future versions of <code class="docutils literal notranslate"><span class="pre">LUdecomposition_simple()</span></code> may use
<code class="docutils literal notranslate"><span class="pre">_find_reasonable_pivot()</span></code>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition" title="sympy.matrices.matrices.MatrixBase.LUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixBase.LUdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecompositionFF" title="sympy.matrices.matrices.MatrixBase.LUdecompositionFF"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUdecompositionFF</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.LUsolve">
<span class="sig-name descname"><span class="pre">LUsolve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">rhs</span></em>, <em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2177-L2178"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solve the linear system <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">rhs</span></code> for <code class="docutils literal notranslate"><span class="pre">x</span></code> where <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">=</span> <span class="pre">M</span></code>.</p>
<p>This is for symbolic matrices, for real or complex ones use
mpmath.lu_solve or mpmath.qr_solve.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.lower_triangular_solve" title="sympy.matrices.dense.DenseMatrix.lower_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.lower_triangular_solve</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.upper_triangular_solve" title="sympy.matrices.dense.DenseMatrix.upper_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.upper_triangular_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.gauss_jordan_solve" title="sympy.matrices.matrices.MatrixBase.gauss_jordan_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">gauss_jordan_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.cholesky_solve" title="sympy.matrices.matrices.MatrixBase.cholesky_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cholesky_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.diagonal_solve" title="sympy.matrices.matrices.MatrixBase.diagonal_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonal_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LDLsolve" title="sympy.matrices.matrices.MatrixBase.LDLsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LDLsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="sympy.matrices.matrices.MatrixBase.QRsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv_solve" title="sympy.matrices.matrices.MatrixBase.pinv_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition" title="sympy.matrices.matrices.MatrixBase.LUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUdecomposition</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.QRdecomposition">
<span class="sig-name descname"><span class="pre">QRdecomposition</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2156-L2157"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.QRdecomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a QR decomposition.</p>
<p class="rubric">Explanation</p>
<p>A QR decomposition is a decomposition in the form <span class="math notranslate nohighlight">\(A = Q R\)</span>
where</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(Q\)</span> is a column orthogonal matrix.</p></li>
<li><p><span class="math notranslate nohighlight">\(R\)</span> is a upper triangular (trapezoidal) matrix.</p></li>
</ul>
<p>A column orthogonal matrix satisfies
<span class="math notranslate nohighlight">\(\mathbb{I} = Q^H Q\)</span> while a full orthogonal matrix satisfies
relation <span class="math notranslate nohighlight">\(\mathbb{I} = Q Q^H = Q^H Q\)</span> where <span class="math notranslate nohighlight">\(I\)</span> is an identity
matrix with matching dimensions.</p>
<p>For matrices which are not square or are rank-deficient, it is
sufficient to return a column orthogonal matrix because augmenting
them may introduce redundant computations.
And an another advantage of this is that you can easily inspect the
matrix rank by counting the number of columns of <span class="math notranslate nohighlight">\(Q\)</span>.</p>
<p>If you want to augment the results to return a full orthogonal
decomposition, you should use the following procedures.</p>
<ul class="simple">
<li><p>Augment the <span class="math notranslate nohighlight">\(Q\)</span> matrix with columns that are orthogonal to every
other columns and make it square.</p></li>
<li><p>Augument the <span class="math notranslate nohighlight">\(R\)</span> matrix with zero rows to make it have the same
shape as the original matrix.</p></li>
</ul>
<p>The procedure will be illustrated in the examples section.</p>
<p class="rubric">Examples</p>
<p>A full rank matrix example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">12</span><span class="p">,</span> <span class="o">-</span><span class="mi">51</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">6</span><span class="p">,</span> <span class="mi">167</span><span class="p">,</span> <span class="o">-</span><span class="mi">68</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span> <span class="mi">24</span><span class="p">,</span> <span class="o">-</span><span class="mi">41</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="p">,</span> <span class="n">R</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">QRdecomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span>
<span class="go">Matrix([</span>
<span class="go">[ 6/7, -69/175, -58/175],</span>
<span class="go">[ 3/7, 158/175,   6/175],</span>
<span class="go">[-2/7,    6/35,  -33/35]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span>
<span class="go">Matrix([</span>
<span class="go">[14,  21, -14],</span>
<span class="go">[ 0, 175, -70],</span>
<span class="go">[ 0,   0,  35]])</span>
</pre></div>
</div>
<p>If the matrix is square and full rank, the <span class="math notranslate nohighlight">\(Q\)</span> matrix becomes
orthogonal in both directions, and needs no augmentation.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span> <span class="o">*</span> <span class="n">Q</span><span class="o">.</span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="o">.</span><span class="n">H</span> <span class="o">*</span> <span class="n">Q</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">==</span> <span class="n">Q</span><span class="o">*</span><span class="n">R</span>
<span class="go">True</span>
</pre></div>
</div>
<p>A rank deficient matrix example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">12</span><span class="p">,</span> <span class="o">-</span><span class="mi">51</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">6</span><span class="p">,</span> <span class="mi">167</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span> <span class="mi">24</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="p">,</span> <span class="n">R</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">QRdecomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span>
<span class="go">Matrix([</span>
<span class="go">[ 6/7, -69/175],</span>
<span class="go">[ 3/7, 158/175],</span>
<span class="go">[-2/7,    6/35]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span>
<span class="go">Matrix([</span>
<span class="go">[14,  21, 0],</span>
<span class="go">[ 0, 175, 0]])</span>
</pre></div>
</div>
<p>QRdecomposition might return a matrix Q that is rectangular.
In this case the orthogonality condition might be satisfied as
<span class="math notranslate nohighlight">\(\mathbb{I} = Q.H*Q\)</span> but not in the reversed product
<span class="math notranslate nohighlight">\(\mathbb{I} = Q * Q.H\)</span>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="o">.</span><span class="n">H</span> <span class="o">*</span> <span class="n">Q</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0],</span>
<span class="go">[0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span> <span class="o">*</span> <span class="n">Q</span><span class="o">.</span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[27261/30625,   348/30625, -1914/6125],</span>
<span class="go">[  348/30625, 30589/30625,   198/6125],</span>
<span class="go">[ -1914/6125,    198/6125,   136/1225]])</span>
</pre></div>
</div>
<p>If you want to augment the results to be a full orthogonal
decomposition, you should augment <span class="math notranslate nohighlight">\(Q\)</span> with an another orthogonal
column.</p>
<p>You are able to append an arbitrary standard basis that are linearly
independent to every other columns and you can run the Gram-Schmidt
process to make them augmented as orthogonal basis.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Q_aug</span> <span class="o">=</span> <span class="n">Q</span><span class="o">.</span><span class="n">row_join</span><span class="p">(</span><span class="n">Matrix</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q_aug</span> <span class="o">=</span> <span class="n">Q_aug</span><span class="o">.</span><span class="n">QRdecomposition</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q_aug</span>
<span class="go">Matrix([</span>
<span class="go">[ 6/7, -69/175, 58/175],</span>
<span class="go">[ 3/7, 158/175, -6/175],</span>
<span class="go">[-2/7,    6/35,  33/35]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q_aug</span><span class="o">.</span><span class="n">H</span> <span class="o">*</span> <span class="n">Q_aug</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q_aug</span> <span class="o">*</span> <span class="n">Q_aug</span><span class="o">.</span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
</pre></div>
</div>
<p>Augmenting the <span class="math notranslate nohighlight">\(R\)</span> matrix with zero row is straightforward.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">R_aug</span> <span class="o">=</span> <span class="n">R</span><span class="o">.</span><span class="n">col_join</span><span class="p">(</span><span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R_aug</span>
<span class="go">Matrix([</span>
<span class="go">[14,  21, 0],</span>
<span class="go">[ 0, 175, 0],</span>
<span class="go">[ 0,   0, 0]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q_aug</span> <span class="o">*</span> <span class="n">R_aug</span> <span class="o">==</span> <span class="n">A</span>
<span class="go">True</span>
</pre></div>
</div>
<p>A zero matrix example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="p">,</span> <span class="n">R</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">QRdecomposition</span><span class="p">()</span>
</pre></div>
</div>
<p>They may return matrices with zero rows and columns.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span>
<span class="go">Matrix(3, 0, [])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span>
<span class="go">Matrix(0, 4, [])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="o">*</span><span class="n">R</span>
<span class="go">Matrix([</span>
<span class="go">[0, 0, 0, 0],</span>
<span class="go">[0, 0, 0, 0],</span>
<span class="go">[0, 0, 0, 0]])</span>
</pre></div>
</div>
<p>As the same augmentation rule described above, <span class="math notranslate nohighlight">\(Q\)</span> can be augmented
with columns of an identity matrix and <span class="math notranslate nohighlight">\(R\)</span> can be augmented with
rows of a zero matrix.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Q_aug</span> <span class="o">=</span> <span class="n">Q</span><span class="o">.</span><span class="n">row_join</span><span class="p">(</span><span class="n">Matrix</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R_aug</span> <span class="o">=</span> <span class="n">R</span><span class="o">.</span><span class="n">col_join</span><span class="p">(</span><span class="n">Matrix</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q_aug</span> <span class="o">*</span> <span class="n">Q_aug</span><span class="o">.</span><span class="n">T</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R_aug</span>
<span class="go">Matrix([</span>
<span class="go">[0, 0, 0, 0],</span>
<span class="go">[0, 0, 0, 0],</span>
<span class="go">[0, 0, 0, 0]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q_aug</span> <span class="o">*</span> <span class="n">R_aug</span> <span class="o">==</span> <span class="n">A</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.cholesky" title="sympy.matrices.dense.DenseMatrix.cholesky"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.cholesky</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.LDLdecomposition" title="sympy.matrices.dense.DenseMatrix.LDLdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.LDLdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition" title="sympy.matrices.matrices.MatrixBase.LUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixBase.LUdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="sympy.matrices.matrices.MatrixBase.QRsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRsolve</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.QRsolve">
<span class="sig-name descname"><span class="pre">QRsolve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2180-L2181"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solve the linear system <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">b</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">M</span></code> is the matrix <code class="docutils literal notranslate"><span class="pre">A</span></code>, the method argument is the vector
<code class="docutils literal notranslate"><span class="pre">b</span></code>.  The method returns the solution vector <code class="docutils literal notranslate"><span class="pre">x</span></code>.  If <code class="docutils literal notranslate"><span class="pre">b</span></code> is a
matrix, the system is solved for each column of <code class="docutils literal notranslate"><span class="pre">b</span></code> and the
return value is a matrix of the same shape as <code class="docutils literal notranslate"><span class="pre">b</span></code>.</p>
<p>This method is slower (approximately by a factor of 2) but
more stable for floating-point arithmetic than the LUsolve method.
However, LUsolve usually uses an exact arithmetic, so you don’t need
to use QRsolve.</p>
<p>This is mainly for educational purposes and symbolic matrices, for real
(or complex) matrices use mpmath.qr_solve.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.lower_triangular_solve" title="sympy.matrices.dense.DenseMatrix.lower_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.lower_triangular_solve</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.upper_triangular_solve" title="sympy.matrices.dense.DenseMatrix.upper_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.upper_triangular_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.gauss_jordan_solve" title="sympy.matrices.matrices.MatrixBase.gauss_jordan_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">gauss_jordan_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.cholesky_solve" title="sympy.matrices.matrices.MatrixBase.cholesky_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cholesky_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.diagonal_solve" title="sympy.matrices.matrices.MatrixBase.diagonal_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonal_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LDLsolve" title="sympy.matrices.matrices.MatrixBase.LDLsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LDLsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv_solve" title="sympy.matrices.matrices.MatrixBase.pinv_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRdecomposition" title="sympy.matrices.matrices.MatrixBase.QRdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRdecomposition</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.add">
<span class="sig-name descname"><span class="pre">add</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1221-L1223"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.add" title="Permalink to this definition">¶</a></dt>
<dd><p>Return self + b</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.analytic_func">
<span class="sig-name descname"><span class="pre">analytic_func</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1527-L1620"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.analytic_func" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes f(A) where A is a Square Matrix
and f is an analytic function.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>f</strong> : Expr</p>
<blockquote>
<div><p>Analytic Function</p>
</div></blockquote>
<p><strong>x</strong> : Symbol</p>
<blockquote>
<div><p>parameter of f</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">log</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">S</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">analytic_func</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[     0, log(2)],</span>
<span class="go">[log(2),      0]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.cholesky">
<span class="sig-name descname"><span class="pre">cholesky</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">hermitian</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2134-L2135"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.cholesky" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the Cholesky-type decomposition L of a matrix A
such that L * L.H == A if hermitian flag is True,
or L * L.T == A if hermitian is False.</p>
<p>A must be a Hermitian positive-definite matrix if hermitian is True,
or a symmetric matrix if it is False.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(((</span><span class="mi">25</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="o">-</span><span class="mi">5</span><span class="p">),</span> <span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="mi">18</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">11</span><span class="p">)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">cholesky</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[ 5, 0, 0],</span>
<span class="go">[ 3, 3, 0],</span>
<span class="go">[-1, 1, 3]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">cholesky</span><span class="p">()</span> <span class="o">*</span> <span class="n">A</span><span class="o">.</span><span class="n">cholesky</span><span class="p">()</span><span class="o">.</span><span class="n">T</span>
<span class="go">Matrix([</span>
<span class="go">[25, 15, -5],</span>
<span class="go">[15, 18,  0],</span>
<span class="go">[-5,  0, 11]])</span>
</pre></div>
</div>
<p>The matrix can have complex entries:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(((</span><span class="mi">9</span><span class="p">,</span> <span class="mi">3</span><span class="o">*</span><span class="n">I</span><span class="p">),</span> <span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="o">*</span><span class="n">I</span><span class="p">,</span> <span class="mi">5</span><span class="p">)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">cholesky</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[ 3, 0],</span>
<span class="go">[-I, 2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">cholesky</span><span class="p">()</span> <span class="o">*</span> <span class="n">A</span><span class="o">.</span><span class="n">cholesky</span><span class="p">()</span><span class="o">.</span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[   9, 3*I],</span>
<span class="go">[-3*I,   5]])</span>
</pre></div>
</div>
<p>Non-hermitian Cholesky-type decomposition may be useful when the
matrix is not positive-definite.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">cholesky</span><span class="p">(</span><span class="n">hermitian</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span>
<span class="go">Matrix([</span>
<span class="go">[1,         0],</span>
<span class="go">[2, sqrt(3)*I]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span><span class="o">*</span><span class="n">L</span><span class="o">.</span><span class="n">T</span> <span class="o">==</span> <span class="n">A</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.LDLdecomposition" title="sympy.matrices.dense.DenseMatrix.LDLdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.LDLdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUdecomposition" title="sympy.matrices.matrices.MatrixBase.LUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixBase.LUdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRdecomposition" title="sympy.matrices.matrices.MatrixBase.QRdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRdecomposition</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.cholesky_solve">
<span class="sig-name descname"><span class="pre">cholesky_solve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2171-L2172"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.cholesky_solve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solves <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">B</span></code> using Cholesky decomposition,
for a general square non-singular matrix.
For a non-square matrix with rows &gt; cols,
the least squares solution is returned.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.lower_triangular_solve" title="sympy.matrices.dense.DenseMatrix.lower_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.lower_triangular_solve</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.upper_triangular_solve" title="sympy.matrices.dense.DenseMatrix.upper_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.upper_triangular_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.gauss_jordan_solve" title="sympy.matrices.matrices.MatrixBase.gauss_jordan_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">gauss_jordan_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.diagonal_solve" title="sympy.matrices.matrices.MatrixBase.diagonal_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonal_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LDLsolve" title="sympy.matrices.matrices.MatrixBase.LDLsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LDLsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="sympy.matrices.matrices.MatrixBase.QRsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv_solve" title="sympy.matrices.matrices.MatrixBase.pinv_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv_solve</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.condition_number">
<span class="sig-name descname"><span class="pre">condition_number</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1225-L1247"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.condition_number" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the condition number of a matrix.</p>
<p>This is the maximum singular value divided by the minimum singular value</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">One</span><span class="o">/</span><span class="mi">10</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">condition_number</span><span class="p">()</span>
<span class="go">100</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixEigen.singular_values" title="sympy.matrices.matrices.MatrixEigen.singular_values"><code class="xref py py-obj docutils literal notranslate"><span class="pre">singular_values</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.connected_components">
<span class="sig-name descname"><span class="pre">connected_components</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2226-L2227"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.connected_components" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of connected vertices of the graph when
a square matrix is viewed as a weighted graph.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">66</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">68</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">67</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">55</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">54</span><span class="p">,</span> <span class="mi">53</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">86</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">88</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">87</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">21</span><span class="p">,</span> <span class="mi">22</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">44</span><span class="p">,</span> <span class="mi">43</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">35</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">34</span><span class="p">,</span> <span class="mi">33</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">76</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">78</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">77</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">connected_components</span><span class="p">()</span>
<span class="go">[[0, 3, 8], [1, 6, 7], [2, 4, 5]]</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Even if any symbolic elements of the matrix can be indeterminate
to be zero mathematically, this only takes the account of the
structural aspect of the matrix, so they will considered to be
nonzero.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.connected_components_decomposition">
<span class="sig-name descname"><span class="pre">connected_components_decomposition</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2229-L2230"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.connected_components_decomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Decomposes a square matrix into block diagonal form only
using the permutations.</p>
<dl class="field-list">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p><strong>P, B</strong> : PermutationMatrix, BlockDiagMatrix</p>
<blockquote>
<div><p><em>P</em> is a permutation matrix for the similarity transform
as in the explanation. And <em>B</em> is the block diagonal matrix of
the result of the permutation.</p>
<p>If you would like to get the diagonal blocks from the
BlockDiagMatrix, see
<a class="reference internal" href="expressions.html#sympy.matrices.expressions.blockmatrix.BlockDiagMatrix.get_diag_blocks" title="sympy.matrices.expressions.blockmatrix.BlockDiagMatrix.get_diag_blocks"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_diag_blocks()</span></code></a>.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The decomposition is in a form of <span class="math notranslate nohighlight">\(A = P^{-1} B P\)</span> where <span class="math notranslate nohighlight">\(P\)</span> is a
permutation matrix and <span class="math notranslate nohighlight">\(B\)</span> is a block diagonal matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">pprint</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">66</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">68</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">67</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">55</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">54</span><span class="p">,</span> <span class="mi">53</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">86</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">88</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">87</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">21</span><span class="p">,</span> <span class="mi">22</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">44</span><span class="p">,</span> <span class="mi">43</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">35</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">34</span><span class="p">,</span> <span class="mi">33</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">76</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">78</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">77</span><span class="p">]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">,</span> <span class="n">B</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">connected_components_decomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">P</span><span class="p">)</span>
<span class="go">PermutationMatrix((1 3)(2 8 5 7 4 6))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="go">[[66  68  67]                            ]</span>
<span class="go">[[          ]                            ]</span>
<span class="go">[[86  88  87]       0             0      ]</span>
<span class="go">[[          ]                            ]</span>
<span class="go">[[76  78  77]                            ]</span>
<span class="go">[                                        ]</span>
<span class="go">[              [55  54  53]              ]</span>
<span class="go">[              [          ]              ]</span>
<span class="go">[     0        [45  44  43]       0      ]</span>
<span class="go">[              [          ]              ]</span>
<span class="go">[              [35  34  33]              ]</span>
<span class="go">[                                        ]</span>
<span class="go">[                            [0   1   2 ]]</span>
<span class="go">[                            [          ]]</span>
<span class="go">[     0             0        [10  11  12]]</span>
<span class="go">[                            [          ]]</span>
<span class="go">[                            [20  21  22]]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">B</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">B</span><span class="o">*</span><span class="n">P</span> <span class="o">==</span> <span class="n">A</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>This problem corresponds to the finding of the connected components
of a graph, when a matrix is viewed as a weighted graph.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.copy">
<span class="sig-name descname"><span class="pre">copy</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1249-L1264"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the copy of a matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[1, 2],</span>
<span class="go">[3, 4]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.cross">
<span class="sig-name descname"><span class="pre">cross</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1266-L1298"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.cross" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the cross product of <code class="docutils literal notranslate"><span class="pre">self</span></code> and <code class="docutils literal notranslate"><span class="pre">b</span></code> relaxing the condition
of compatible dimensions: if each has 3 elements, a matrix of the
same type and shape as <code class="docutils literal notranslate"><span class="pre">self</span></code> will be returned. If <code class="docutils literal notranslate"><span class="pre">b</span></code> has the same
shape as <code class="docutils literal notranslate"><span class="pre">self</span></code> then common identities for the cross product (like
<span class="math notranslate nohighlight">\(a \times b = - b \times a\)</span>) will hold.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>b</strong> : 3x1 or 1x3 Matrix</p>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.dot" title="sympy.matrices.matrices.MatrixBase.dot"><code class="xref py py-obj docutils literal notranslate"><span class="pre">dot</span></code></a>, <a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.multiply" title="sympy.matrices.common.MatrixCommon.multiply"><code class="xref py py-obj docutils literal notranslate"><span class="pre">multiply</span></code></a>, <a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.multiply_elementwise" title="sympy.matrices.common.MatrixCommon.multiply_elementwise"><code class="xref py py-obj docutils literal notranslate"><span class="pre">multiply_elementwise</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.diagonal_solve">
<span class="sig-name descname"><span class="pre">diagonal_solve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2162-L2163"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.diagonal_solve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solves <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">B</span></code> efficiently, where A is a diagonal Matrix,
with non-zero diagonal entries.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">eye</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">eye</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">diagonal_solve</span><span class="p">(</span><span class="n">B</span><span class="p">)</span> <span class="o">==</span> <span class="n">B</span><span class="o">/</span><span class="mi">2</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.lower_triangular_solve" title="sympy.matrices.dense.DenseMatrix.lower_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.lower_triangular_solve</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.upper_triangular_solve" title="sympy.matrices.dense.DenseMatrix.upper_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.upper_triangular_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.gauss_jordan_solve" title="sympy.matrices.matrices.MatrixBase.gauss_jordan_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">gauss_jordan_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.cholesky_solve" title="sympy.matrices.matrices.MatrixBase.cholesky_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cholesky_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LDLsolve" title="sympy.matrices.matrices.MatrixBase.LDLsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LDLsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="sympy.matrices.matrices.MatrixBase.QRsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv_solve" title="sympy.matrices.matrices.MatrixBase.pinv_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv_solve</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.dot">
<span class="sig-name descname"><span class="pre">dot</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hermitian</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">conjugate_convention</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1343-L1446"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.dot" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the dot or inner product of two vectors of equal length.
Here <code class="docutils literal notranslate"><span class="pre">self</span></code> must be a <code class="docutils literal notranslate"><span class="pre">Matrix</span></code> of size 1 x n or n x 1, and <code class="docutils literal notranslate"><span class="pre">b</span></code>
must be either a matrix of size 1 x n, n x 1, or a list/tuple of length n.
A scalar is returned.</p>
<p>By default, <code class="docutils literal notranslate"><span class="pre">dot</span></code> does not conjugate <code class="docutils literal notranslate"><span class="pre">self</span></code> or <code class="docutils literal notranslate"><span class="pre">b</span></code>, even if there are
complex entries. Set <code class="docutils literal notranslate"><span class="pre">hermitian=True</span></code> (and optionally a <code class="docutils literal notranslate"><span class="pre">conjugate_convention</span></code>)
to compute the hermitian inner product.</p>
<p>Possible kwargs are <code class="docutils literal notranslate"><span class="pre">hermitian</span></code> and <code class="docutils literal notranslate"><span class="pre">conjugate_convention</span></code>.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">conjugate_convention</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;left&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">&quot;math&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;maths&quot;</span></code>,
the conjugate of the first vector (<code class="docutils literal notranslate"><span class="pre">self</span></code>) is used.  If <code class="docutils literal notranslate"><span class="pre">&quot;right&quot;</span></code>
or <code class="docutils literal notranslate"><span class="pre">&quot;physics&quot;</span></code> is specified, the conjugate of the second vector <code class="docutils literal notranslate"><span class="pre">b</span></code> is used.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">row</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">col</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="go">12</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">row</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="go">10</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="o">*</span><span class="n">I</span><span class="p">,</span> <span class="mi">1</span><span class="o">*</span><span class="n">I</span><span class="p">,</span> <span class="mi">1</span><span class="o">*</span><span class="n">I</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="n">hermitian</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">-3</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="n">hermitian</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">3</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">q1</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="o">*</span><span class="n">I</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">q1</span><span class="p">,</span> <span class="n">hermitian</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">conjugate_convention</span><span class="o">=</span><span class="s2">&quot;maths&quot;</span><span class="p">)</span>
<span class="go">1 - 2*I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">q1</span><span class="p">,</span> <span class="n">hermitian</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">conjugate_convention</span><span class="o">=</span><span class="s2">&quot;physics&quot;</span><span class="p">)</span>
<span class="go">1 + 2*I</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.cross" title="sympy.matrices.matrices.MatrixBase.cross"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cross</span></code></a>, <a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.multiply" title="sympy.matrices.common.MatrixCommon.multiply"><code class="xref py py-obj docutils literal notranslate"><span class="pre">multiply</span></code></a>, <a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.multiply_elementwise" title="sympy.matrices.common.MatrixCommon.multiply_elementwise"><code class="xref py py-obj docutils literal notranslate"><span class="pre">multiply_elementwise</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.dual">
<span class="sig-name descname"><span class="pre">dual</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1448-L1485"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.dual" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the dual of a matrix, which is:</p>
<p><code class="docutils literal notranslate"><span class="pre">(1/2)*levicivita(i,</span> <span class="pre">j,</span> <span class="pre">k,</span> <span class="pre">l)*M(k,</span> <span class="pre">l)</span></code> summed over indices <span class="math notranslate nohighlight">\(k\)</span> and <span class="math notranslate nohighlight">\(l\)</span></p>
<p>Since the levicivita method is anti_symmetric for any pairwise
exchange of indices, the dual of a symmetric matrix is the zero
matrix. Strictly speaking the dual defined here assumes that the
‘matrix’ <span class="math notranslate nohighlight">\(M\)</span> is a contravariant anti_symmetric second rank tensor,
so that the dual is a covariant second rank tensor.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.exp">
<span class="sig-name descname"><span class="pre">exp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1623-L1658"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.exp" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the exponential of a square matrix</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Matrix</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span> <span class="o">*</span> <span class="n">t</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">exp</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[    exp(I*t)/2 + exp(-I*t)/2, -I*exp(I*t)/2 + I*exp(-I*t)/2],</span>
<span class="go">[I*exp(I*t)/2 - I*exp(-I*t)/2,      exp(I*t)/2 + exp(-I*t)/2]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.gauss_jordan_solve">
<span class="sig-name descname"><span class="pre">gauss_jordan_solve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">B</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">freevar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2183-L2184"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.gauss_jordan_solve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solves <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">B</span></code> using Gauss Jordan elimination.</p>
<p>There may be zero, one, or infinite solutions.  If one solution
exists, it will be returned. If infinite solutions exist, it will
be returned parametrically. If no solutions exist, It will throw
ValueError.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>B</strong> : Matrix</p>
<blockquote>
<div><p>The right hand side of the equation to be solved for.  Must have
the same number of rows as matrix A.</p>
</div></blockquote>
<p><strong>freevar</strong> : boolean, optional</p>
<blockquote>
<div><p>Flag, when set to <span class="math notranslate nohighlight">\(True\)</span> will return the indices of the free
variables in the solutions (column Matrix), for a system that is
undetermined (e.g. A has more columns than rows), for which
infinite solutions are possible, in terms of arbitrary
values of free variables. Default <span class="math notranslate nohighlight">\(False\)</span>.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>x</strong> : Matrix</p>
<blockquote>
<div><p>The matrix that will satisfy <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">B</span></code>.  Will have as many rows as
matrix A has columns, and as many columns as matrix B.</p>
</div></blockquote>
<p><strong>params</strong> : Matrix</p>
<blockquote>
<div><p>If the system is underdetermined (e.g. A has more columns than
rows), infinite solutions are possible, in terms of arbitrary
parameters. These arbitrary parameters are returned as params
Matrix.</p>
</div></blockquote>
<p><strong>free_var_index</strong> : List, optional</p>
<blockquote>
<div><p>If the system is underdetermined (e.g. A has more columns than
rows), infinite solutions are possible, in terms of arbitrary
values of free variables. Then the indices of the free variables
in the solutions (column Matrix) are returned by free_var_index,
if the flag <span class="math notranslate nohighlight">\(freevar\)</span> is set to <span class="math notranslate nohighlight">\(True\)</span>.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">6</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">7</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">gauss_jordan_solve</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol</span>
<span class="go">Matrix([</span>
<span class="go">[-2*tau0 - 3*tau1 + 2],</span>
<span class="go">[                 tau0],</span>
<span class="go">[           2*tau1 + 5],</span>
<span class="go">[                 tau1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">params</span>
<span class="go">Matrix([</span>
<span class="go">[tau0],</span>
<span class="go">[tau1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">taus_zeroes</span> <span class="o">=</span> <span class="p">{</span> <span class="n">tau</span><span class="p">:</span><span class="mi">0</span> <span class="k">for</span> <span class="n">tau</span> <span class="ow">in</span> <span class="n">params</span> <span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol_unique</span> <span class="o">=</span> <span class="n">sol</span><span class="o">.</span><span class="n">xreplace</span><span class="p">(</span><span class="n">taus_zeroes</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol_unique</span>
<span class="go">    Matrix([</span>
<span class="go">[2],</span>
<span class="go">[0],</span>
<span class="go">[5],</span>
<span class="go">[0]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">10</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">9</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">gauss_jordan_solve</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol</span>
<span class="go">Matrix([</span>
<span class="go">[-1],</span>
<span class="go">[ 2],</span>
<span class="go">[ 0]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">params</span>
<span class="go">Matrix(0, 1, [])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">7</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="o">-</span><span class="mi">21</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">12</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">gauss_jordan_solve</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol</span>
<span class="go">Matrix([</span>
<span class="go">[0, -2],</span>
<span class="go">[3, -1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">params</span>
<span class="go">Matrix(0, 2, [])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">6</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">7</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="n">freevars</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">gauss_jordan_solve</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">freevar</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sol</span>
<span class="go">Matrix([</span>
<span class="go">[-2*tau0 - 3*tau1 + 2],</span>
<span class="go">[                 tau0],</span>
<span class="go">[           2*tau1 + 5],</span>
<span class="go">[                 tau1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">params</span>
<span class="go">Matrix([</span>
<span class="go">[tau0],</span>
<span class="go">[tau1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">freevars</span>
<span class="go">[1, 3]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.lower_triangular_solve" title="sympy.matrices.dense.DenseMatrix.lower_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.lower_triangular_solve</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.upper_triangular_solve" title="sympy.matrices.dense.DenseMatrix.upper_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.upper_triangular_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.cholesky_solve" title="sympy.matrices.matrices.MatrixBase.cholesky_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cholesky_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.diagonal_solve" title="sympy.matrices.matrices.MatrixBase.diagonal_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonal_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LDLsolve" title="sympy.matrices.matrices.MatrixBase.LDLsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LDLsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="sympy.matrices.matrices.MatrixBase.QRsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv" title="sympy.matrices.matrices.MatrixBase.pinv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r546"><span class="brackets"><a class="fn-backref" href="#id22">R546</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Gaussian_elimination">https://en.wikipedia.org/wiki/Gaussian_elimination</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.inv">
<span class="sig-name descname"><span class="pre">inv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">method=None</span></em>, <em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em>, <em class="sig-param"><span class="pre">try_block_diag=False</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2222-L2224"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.inv" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the inverse of a matrix using the method indicated. Default for
dense matrices is is Gauss elimination, default for sparse matrices is LDL.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>method</strong> : (‘GE’, ‘LU’, ‘ADJ’, ‘CH’, ‘LDL’)</p>
<p><strong>iszerofunc</strong> : function, optional</p>
<blockquote>
<div><p>Zero-testing function to use.</p>
</div></blockquote>
<p><strong>try_block_diag</strong> : bool, optional</p>
<blockquote>
<div><p>If True then will try to form block diagonal matrices using the
method get_diag_blocks(), invert these individually, and then
reconstruct the full inverse matrix.</p>
</div></blockquote>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><p><strong>ValueError</strong></p>
<blockquote>
<div><p>If the determinant of the matrix is zero.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">SparseMatrix</span><span class="p">,</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">SparseMatrix</span><span class="p">([</span>
<span class="gp">... </span><span class="p">[</span> <span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span>  <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span>  <span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span>
<span class="gp">... </span><span class="p">[</span> <span class="mi">0</span><span class="p">,</span>  <span class="mi">0</span><span class="p">,</span>  <span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="s1">&#39;CH&#39;</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[2/3, 1/3, 1/6],</span>
<span class="go">[1/3, 2/3, 1/3],</span>
<span class="go">[  0,   0, 1/2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s1">&#39;LDL&#39;</span><span class="p">)</span> <span class="c1"># use of &#39;method=&#39; is optional</span>
<span class="go">Matrix([</span>
<span class="go">[2/3, 1/3, 1/6],</span>
<span class="go">[1/3, 2/3, 1/3],</span>
<span class="go">[  0,   0, 1/2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">*</span> <span class="n">_</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="s1">&#39;CH&#39;</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[2/3, 1/3, 1/6],</span>
<span class="go">[1/3, 2/3, 1/3],</span>
<span class="go">[  0,   0, 1/2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="s1">&#39;ADJ&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="s1">&#39;GE&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="s1">&#39;LU&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="s1">&#39;CH&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="s1">&#39;LDL&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="n">A</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="s1">&#39;QR&#39;</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>According to the <code class="docutils literal notranslate"><span class="pre">method</span></code> keyword, it calls the appropriate method:</p>
<blockquote>
<div><p>GE …. inverse_GE(); default for dense matrices
LU …. inverse_LU()
ADJ … inverse_ADJ()
CH … inverse_CH()
LDL … inverse_LDL(); default for sparse matrices
QR … inverse_QR()</p>
</div></blockquote>
<p>Note, the GE and LU methods may require the matrix to be simplified
before it is inverted in order to properly detect zeros during
pivoting. In difficult cases a custom zero detection function can
be provided by setting the <code class="docutils literal notranslate"><span class="pre">iszerofunc</span></code> argument to a function that
should return True if its argument is zero. The ADJ routine computes
the determinant and uses that to detect singular matrices in addition
to testing for zeros on the diagonal.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_ADJ" title="sympy.matrices.matrices.MatrixBase.inverse_ADJ"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_ADJ</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_GE" title="sympy.matrices.matrices.MatrixBase.inverse_GE"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_GE</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LU" title="sympy.matrices.matrices.MatrixBase.inverse_LU"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LU</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_CH" title="sympy.matrices.matrices.MatrixBase.inverse_CH"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_CH</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LDL" title="sympy.matrices.matrices.MatrixBase.inverse_LDL"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LDL</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.inv_mod">
<span class="sig-name descname"><span class="pre">inv_mod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">m</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2198-L2199"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.inv_mod" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the inverse of the matrix <span class="math notranslate nohighlight">\(K\)</span> (mod <span class="math notranslate nohighlight">\(m\)</span>), if it exists.</p>
<p>Method to find the matrix inverse of <span class="math notranslate nohighlight">\(K\)</span> (mod <span class="math notranslate nohighlight">\(m\)</span>) implemented in this function:</p>
<ul class="simple">
<li><p>Compute <span class="math notranslate nohighlight">\(\mathrm{adj}(K) = \mathrm{cof}(K)^t\)</span>, the adjoint matrix of <span class="math notranslate nohighlight">\(K\)</span>.</p></li>
<li><p>Compute <span class="math notranslate nohighlight">\(r = 1/\mathrm{det}(K) \pmod m\)</span>.</p></li>
<li><p><span class="math notranslate nohighlight">\(K^{-1} = r\cdot \mathrm{adj}(K) \pmod m\)</span>.</p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">inv_mod</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[3, 1],</span>
<span class="go">[4, 2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">inv_mod</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1, 1],</span>
<span class="go">[0, 1]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.inverse_ADJ">
<span class="sig-name descname"><span class="pre">inverse_ADJ</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2201-L2202"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.inverse_ADJ" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the inverse using the adjugate matrix and a determinant.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inv" title="sympy.matrices.matrices.MatrixBase.inv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inv</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_GE" title="sympy.matrices.matrices.MatrixBase.inverse_GE"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_GE</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LU" title="sympy.matrices.matrices.MatrixBase.inverse_LU"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LU</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_CH" title="sympy.matrices.matrices.MatrixBase.inverse_CH"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_CH</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LDL" title="sympy.matrices.matrices.MatrixBase.inverse_LDL"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LDL</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.inverse_BLOCK">
<span class="sig-name descname"><span class="pre">inverse_BLOCK</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2204-L2205"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.inverse_BLOCK" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the inverse using BLOCKWISE inversion.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inv" title="sympy.matrices.matrices.MatrixBase.inv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inv</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_ADJ" title="sympy.matrices.matrices.MatrixBase.inverse_ADJ"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_ADJ</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_GE" title="sympy.matrices.matrices.MatrixBase.inverse_GE"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_GE</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_CH" title="sympy.matrices.matrices.MatrixBase.inverse_CH"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_CH</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LDL" title="sympy.matrices.matrices.MatrixBase.inverse_LDL"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LDL</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.inverse_CH">
<span class="sig-name descname"><span class="pre">inverse_CH</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2213-L2214"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.inverse_CH" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the inverse using cholesky decomposition.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inv" title="sympy.matrices.matrices.MatrixBase.inv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inv</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_ADJ" title="sympy.matrices.matrices.MatrixBase.inverse_ADJ"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_ADJ</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_GE" title="sympy.matrices.matrices.MatrixBase.inverse_GE"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_GE</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LU" title="sympy.matrices.matrices.MatrixBase.inverse_LU"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LU</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LDL" title="sympy.matrices.matrices.MatrixBase.inverse_LDL"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LDL</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.inverse_GE">
<span class="sig-name descname"><span class="pre">inverse_GE</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2207-L2208"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.inverse_GE" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the inverse using Gaussian elimination.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inv" title="sympy.matrices.matrices.MatrixBase.inv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inv</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_ADJ" title="sympy.matrices.matrices.MatrixBase.inverse_ADJ"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_ADJ</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LU" title="sympy.matrices.matrices.MatrixBase.inverse_LU"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LU</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_CH" title="sympy.matrices.matrices.MatrixBase.inverse_CH"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_CH</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LDL" title="sympy.matrices.matrices.MatrixBase.inverse_LDL"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LDL</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.inverse_LDL">
<span class="sig-name descname"><span class="pre">inverse_LDL</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2216-L2217"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.inverse_LDL" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the inverse using LDL decomposition.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inv" title="sympy.matrices.matrices.MatrixBase.inv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inv</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_ADJ" title="sympy.matrices.matrices.MatrixBase.inverse_ADJ"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_ADJ</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_GE" title="sympy.matrices.matrices.MatrixBase.inverse_GE"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_GE</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LU" title="sympy.matrices.matrices.MatrixBase.inverse_LU"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LU</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_CH" title="sympy.matrices.matrices.MatrixBase.inverse_CH"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_CH</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.inverse_LU">
<span class="sig-name descname"><span class="pre">inverse_LU</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2210-L2211"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.inverse_LU" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the inverse using LU decomposition.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inv" title="sympy.matrices.matrices.MatrixBase.inv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inv</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_ADJ" title="sympy.matrices.matrices.MatrixBase.inverse_ADJ"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_ADJ</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_GE" title="sympy.matrices.matrices.MatrixBase.inverse_GE"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_GE</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_CH" title="sympy.matrices.matrices.MatrixBase.inverse_CH"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_CH</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LDL" title="sympy.matrices.matrices.MatrixBase.inverse_LDL"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LDL</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.inverse_QR">
<span class="sig-name descname"><span class="pre">inverse_QR</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2219-L2220"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.inverse_QR" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the inverse using QR decomposition.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inv" title="sympy.matrices.matrices.MatrixBase.inv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inv</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_ADJ" title="sympy.matrices.matrices.MatrixBase.inverse_ADJ"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_ADJ</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_GE" title="sympy.matrices.matrices.MatrixBase.inverse_GE"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_GE</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_CH" title="sympy.matrices.matrices.MatrixBase.inverse_CH"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_CH</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inverse_LDL" title="sympy.matrices.matrices.MatrixBase.inverse_LDL"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inverse_LDL</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.irregular">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">irregular</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ntop</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">matrices</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L864-L905"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.irregular" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a matrix filled by the given matrices which
are listed in order of appearance from left to right, top to
bottom as they first appear in the matrix. They must fill the
matrix completely.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">ones</span><span class="p">,</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="o">.</span><span class="n">irregular</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">ones</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span> <span class="n">ones</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span><span class="o">*</span><span class="mi">2</span><span class="p">,</span> <span class="n">ones</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="mi">3</span><span class="p">,</span>
<span class="gp">... </span>  <span class="n">ones</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="mi">4</span><span class="p">,</span> <span class="n">ones</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="mi">5</span><span class="p">,</span> <span class="n">ones</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="mi">6</span><span class="p">,</span> <span class="n">ones</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="mi">7</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">  [1, 2, 2, 2, 3, 3],</span>
<span class="go">  [1, 2, 2, 2, 3, 3],</span>
<span class="go">  [4, 2, 2, 2, 5, 5],</span>
<span class="go">  [6, 6, 7, 7, 5, 5]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.is_nilpotent">
<span class="sig-name descname"><span class="pre">is_nilpotent</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1781-L1808"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.is_nilpotent" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if a matrix is nilpotent.</p>
<p>A matrix B is nilpotent if for some integer k, B**k is
a zero matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">is_nilpotent</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">is_nilpotent</span><span class="p">()</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.key2bounds">
<span class="sig-name descname"><span class="pre">key2bounds</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">keys</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1810-L1839"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.key2bounds" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts a key with potentially mixed types of keys (integer and slice)
into a tuple of ranges and raises an error if any index is out of <code class="docutils literal notranslate"><span class="pre">self</span></code>’s
range.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.key2ij" title="sympy.matrices.matrices.MatrixBase.key2ij"><code class="xref py py-obj docutils literal notranslate"><span class="pre">key2ij</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.key2ij">
<span class="sig-name descname"><span class="pre">key2ij</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1841-L1861"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.key2ij" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts key into canonical form, converting integers or indexable
items into valid integers for <code class="docutils literal notranslate"><span class="pre">self</span></code>’s range or returning slices
unchanged.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.key2bounds" title="sympy.matrices.matrices.MatrixBase.key2bounds"><code class="xref py py-obj docutils literal notranslate"><span class="pre">key2bounds</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.log">
<span class="sig-name descname"><span class="pre">log</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">simplify=&lt;function</span> <span class="pre">cancel&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1699-L1779"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.log" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the logarithm of a square matrix</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>simplify</strong> : function, bool</p>
<blockquote>
<div><p>The function to simplify the result with.</p>
<p>Default is <code class="docutils literal notranslate"><span class="pre">cancel</span></code>, which is effective to reduce the
expression growing for taking reciprocals and inverses for
symbolic matrices.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">Matrix</span>
</pre></div>
</div>
<p>Examples for positive-definite matrices:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">log</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[0, 1],</span>
<span class="go">[0, 0]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">S</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">log</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[     0, log(2)],</span>
<span class="go">[log(2),      0]])</span>
</pre></div>
</div>
<p>Examples for non positive-definite matrices:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="n">S</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">/</span><span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">log</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[         I*pi/2, log(2) - I*pi/2],</span>
<span class="go">[log(2) - I*pi/2,          I*pi/2]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span>
<span class="gp">... </span>    <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
<span class="gp">... </span>     <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>     <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>     <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">log</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[ I*pi/2,       0,       0, -I*pi/2],</span>
<span class="go">[      0,  I*pi/2, -I*pi/2,       0],</span>
<span class="go">[      0, -I*pi/2,  I*pi/2,       0],</span>
<span class="go">[-I*pi/2,       0,       0,  I*pi/2]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.lower_triangular_solve">
<span class="sig-name descname"><span class="pre">lower_triangular_solve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2165-L2166"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.lower_triangular_solve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solves <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">B</span></code>, where A is a lower triangular matrix.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.upper_triangular_solve" title="sympy.matrices.matrices.MatrixBase.upper_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">upper_triangular_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.gauss_jordan_solve" title="sympy.matrices.matrices.MatrixBase.gauss_jordan_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">gauss_jordan_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.cholesky_solve" title="sympy.matrices.matrices.MatrixBase.cholesky_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cholesky_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.diagonal_solve" title="sympy.matrices.matrices.MatrixBase.diagonal_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonal_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LDLsolve" title="sympy.matrices.matrices.MatrixBase.LDLsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LDLsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="sympy.matrices.matrices.MatrixBase.QRsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv_solve" title="sympy.matrices.matrices.MatrixBase.pinv_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv_solve</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.norm">
<span class="sig-name descname"><span class="pre">norm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ord</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1902-L2000"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.norm" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the Norm of a Matrix or Vector.
In the simplest case this is the geometric size of the vector
Other norms can be specified by the ord parameter</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 8%" />
<col style="width: 47%" />
<col style="width: 44%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>ord</p></th>
<th class="head"><p>norm for matrices</p></th>
<th class="head"><p>norm for vectors</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>None</p></td>
<td><p>Frobenius norm</p></td>
<td><p>2-norm</p></td>
</tr>
<tr class="row-odd"><td><p>‘fro’</p></td>
<td><p>Frobenius norm</p></td>
<td><ul class="simple">
<li><p>does not exist</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>inf</p></td>
<td><p>maximum row sum</p></td>
<td><p>max(abs(x))</p></td>
</tr>
<tr class="row-odd"><td><p>-inf</p></td>
<td><p>–</p></td>
<td><p>min(abs(x))</p></td>
</tr>
<tr class="row-even"><td><p>1</p></td>
<td><p>maximum column sum</p></td>
<td><p>as below</p></td>
</tr>
<tr class="row-odd"><td><p>-1</p></td>
<td><p>–</p></td>
<td><p>as below</p></td>
</tr>
<tr class="row-even"><td><p>2</p></td>
<td><p>2-norm (largest sing. value)</p></td>
<td><p>as below</p></td>
</tr>
<tr class="row-odd"><td><p>-2</p></td>
<td><p>smallest singular value</p></td>
<td><p>as below</p></td>
</tr>
<tr class="row-even"><td><p>other</p></td>
<td><ul class="simple">
<li><p>does not exist</p></li>
</ul>
</td>
<td><p>sum(abs(x)**ord)**(1./ord)</p></td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">trigsimp</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">trigsimp</span><span class="p">(</span> <span class="n">v</span><span class="o">.</span><span class="n">norm</span><span class="p">()</span> <span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">(sin(x)**10 + cos(x)**10)**(1/10)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c1"># maximum sum of absolute values of A is 2</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c1"># Spectral norm (max of |Ax|/|x| under 2-vector-norm)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)</span> <span class="c1"># Inverse spectral norm (smallest singular value)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">norm</span><span class="p">()</span> <span class="c1"># Frobenius Norm</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">oo</span><span class="p">)</span> <span class="c1"># Infinity Norm</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">])</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">oo</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">([</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="o">-</span><span class="n">oo</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.normalized" title="sympy.matrices.matrices.MatrixBase.normalized"><code class="xref py py-obj docutils literal notranslate"><span class="pre">normalized</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.normalized">
<span class="sig-name descname"><span class="pre">normalized</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L1863-L1900"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.normalized" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the normalized version of <code class="docutils literal notranslate"><span class="pre">self</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>iszerofunc</strong> : Function, optional</p>
<blockquote>
<div><p>A function to determine whether <code class="docutils literal notranslate"><span class="pre">self</span></code> is a zero vector.
The default <code class="docutils literal notranslate"><span class="pre">_iszero</span></code> tests to see if each element is
exactly zero.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Matrix</p>
<blockquote>
<div><p>Normalized vector form of <code class="docutils literal notranslate"><span class="pre">self</span></code>.
It has the same length as a unit vector. However, a zero vector
will be returned for a vector with norm 0.</p>
</div></blockquote>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><strong>ShapeError</strong></p>
<blockquote>
<div><p>If the matrix is not in a vector form.</p>
</div></blockquote>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.norm" title="sympy.matrices.matrices.MatrixBase.norm"><code class="xref py py-obj docutils literal notranslate"><span class="pre">norm</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.pinv">
<span class="sig-name descname"><span class="pre">pinv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'RD'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2195-L2196"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.pinv" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate the Moore-Penrose pseudoinverse of the matrix.</p>
<p>The Moore-Penrose pseudoinverse exists and is unique for any matrix.
If the matrix is invertible, the pseudoinverse is the same as the
inverse.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>method</strong> : String, optional</p>
<blockquote>
<div><p>Specifies the method for computing the pseudoinverse.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">'RD'</span></code>, Rank-Decomposition will be used.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">'ED'</span></code>, Diagonalization will be used.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>Computing pseudoinverse by rank decomposition :</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">pinv</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[-17/18,  4/9],</span>
<span class="go">[  -1/9,  1/9],</span>
<span class="go">[ 13/18, -2/9]])</span>
</pre></div>
</div>
<p>Computing pseudoinverse by diagonalization :</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">pinv</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s1">&#39;ED&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span>
<span class="go">Matrix([</span>
<span class="go">[-17/18,  4/9],</span>
<span class="go">[  -1/9,  1/9],</span>
<span class="go">[ 13/18, -2/9]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.inv" title="sympy.matrices.matrices.MatrixBase.inv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inv</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv_solve" title="sympy.matrices.matrices.MatrixBase.pinv_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv_solve</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r547"><span class="brackets"><a class="fn-backref" href="#id23">R547</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse">https://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.pinv_solve">
<span class="sig-name descname"><span class="pre">pinv_solve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">B</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arbitrary_matrix</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2186-L2187"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.pinv_solve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solve <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">B</span></code> using the Moore-Penrose pseudoinverse.</p>
<p>There may be zero, one, or infinite solutions.  If one solution
exists, it will be returned.  If infinite solutions exist, one will
be returned based on the value of arbitrary_matrix.  If no solutions
exist, the least-squares solution is returned.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>B</strong> : Matrix</p>
<blockquote>
<div><p>The right hand side of the equation to be solved for.  Must have
the same number of rows as matrix A.</p>
</div></blockquote>
<p><strong>arbitrary_matrix</strong> : Matrix</p>
<blockquote>
<div><p>If the system is underdetermined (e.g. A has more columns than
rows), infinite solutions are possible, in terms of an arbitrary
matrix.  This parameter may be set to a specific matrix to use
for that purpose; if so, it must be the same shape as x, with as
many rows as matrix A has columns, and as many columns as matrix
B.  If left as None, an appropriate matrix containing dummy
symbols in the form of <code class="docutils literal notranslate"><span class="pre">wn_m</span></code> will be used, with n and m being
row and column position of each symbol.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>x</strong> : Matrix</p>
<blockquote>
<div><p>The matrix that will satisfy <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">B</span></code>.  Will have as many rows as
matrix A has columns, and as many columns as matrix B.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">pinv_solve</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[ _w0_0/6 - _w1_0/3 + _w2_0/6 - 55/18],</span>
<span class="go">[-_w0_0/3 + 2*_w1_0/3 - _w2_0/3 + 1/9],</span>
<span class="go">[ _w0_0/6 - _w1_0/3 + _w2_0/6 + 59/18]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">pinv_solve</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">arbitrary_matrix</span><span class="o">=</span><span class="n">Matrix</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]))</span>
<span class="go">Matrix([</span>
<span class="go">[-55/18],</span>
<span class="go">[   1/9],</span>
<span class="go">[ 59/18]])</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>This may return either exact solutions or least squares solutions.
To determine which, check <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">*</span> <span class="pre">A.pinv()</span> <span class="pre">*</span> <span class="pre">B</span> <span class="pre">==</span> <span class="pre">B</span></code>.  It will be
True if exact solutions exist, and False if only a least-squares
solution exists.  Be aware that the left hand side of that equation
may need to be simplified to correctly compare to the right hand
side.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.lower_triangular_solve" title="sympy.matrices.dense.DenseMatrix.lower_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.lower_triangular_solve</span></code></a>, <a class="reference internal" href="dense.html#sympy.matrices.dense.DenseMatrix.upper_triangular_solve" title="sympy.matrices.dense.DenseMatrix.upper_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.DenseMatrix.upper_triangular_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.gauss_jordan_solve" title="sympy.matrices.matrices.MatrixBase.gauss_jordan_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">gauss_jordan_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.cholesky_solve" title="sympy.matrices.matrices.MatrixBase.cholesky_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cholesky_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.diagonal_solve" title="sympy.matrices.matrices.MatrixBase.diagonal_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonal_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LDLsolve" title="sympy.matrices.matrices.MatrixBase.LDLsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LDLsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="sympy.matrices.matrices.MatrixBase.QRsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv" title="sympy.matrices.matrices.MatrixBase.pinv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r548"><span class="brackets"><a class="fn-backref" href="#id24">R548</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse#Obtaining_all_solutions_of_a_linear_system">https://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse#Obtaining_all_solutions_of_a_linear_system</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.print_nonzero">
<span class="sig-name descname"><span class="pre">print_nonzero</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symb</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'X'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2002-L2034"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.print_nonzero" title="Permalink to this definition">¶</a></dt>
<dd><p>Shows location of non-zero entries for fast shape lookup.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">eye</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">:</span> <span class="n">i</span><span class="o">*</span><span class="mi">3</span><span class="o">+</span><span class="n">j</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span>
<span class="go">Matrix([</span>
<span class="go">[0, 1, 2],</span>
<span class="go">[3, 4, 5]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">print_nonzero</span><span class="p">()</span>
<span class="go">[ XX]</span>
<span class="go">[XXX]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">eye</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">print_nonzero</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
<span class="go">[x   ]</span>
<span class="go">[ x  ]</span>
<span class="go">[  x ]</span>
<span class="go">[   x]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.project">
<span class="sig-name descname"><span class="pre">project</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">v</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2036-L2050"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.project" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the projection of <code class="docutils literal notranslate"><span class="pre">self</span></code> onto the line containing <code class="docutils literal notranslate"><span class="pre">v</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V</span><span class="o">.</span><span class="n">project</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Matrix([[sqrt(3)/2, 0]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V</span><span class="o">.</span><span class="n">project</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="p">)</span>
<span class="go">Matrix([[sqrt(3)/2, 0]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.rank_decomposition">
<span class="sig-name descname"><span class="pre">rank_decomposition</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">iszerofunc=&lt;function</span> <span class="pre">_iszero&gt;</span></em>, <em class="sig-param"><span class="pre">simplify=False</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2130-L2132"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.rank_decomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a pair of matrices (<span class="math notranslate nohighlight">\(C\)</span>, <span class="math notranslate nohighlight">\(F\)</span>) with matching rank
such that <span class="math notranslate nohighlight">\(A = C F\)</span>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>iszerofunc</strong> : Function, optional</p>
<blockquote>
<div><p>A function used for detecting whether an element can
act as a pivot.  <code class="docutils literal notranslate"><span class="pre">lambda</span> <span class="pre">x:</span> <span class="pre">x.is_zero</span></code> is used by default.</p>
</div></blockquote>
<p><strong>simplify</strong> : Bool or Function, optional</p>
<blockquote>
<div><p>A function used to simplify elements when looking for a
pivot. By default SymPy’s <code class="docutils literal notranslate"><span class="pre">simplify</span></code> is used.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>(C, F)</strong> : Matrices</p>
<blockquote>
<div><p><span class="math notranslate nohighlight">\(C\)</span> and <span class="math notranslate nohighlight">\(F\)</span> are full-rank matrices with rank as same as <span class="math notranslate nohighlight">\(A\)</span>,
whose product gives <span class="math notranslate nohighlight">\(A\)</span>.</p>
<p>See Notes for additional mathematical details.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">9</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">8</span><span class="p">]</span>
<span class="gp">... </span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="p">,</span> <span class="n">F</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">rank_decomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span>
<span class="go">Matrix([</span>
<span class="go">[1, 3, 4],</span>
<span class="go">[2, 7, 9],</span>
<span class="go">[1, 5, 1],</span>
<span class="go">[1, 2, 8]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">F</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, -2, 0],</span>
<span class="go">[0, 1,  1, 0],</span>
<span class="go">[0, 0,  0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">*</span> <span class="n">F</span> <span class="o">==</span> <span class="n">A</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Obtaining <span class="math notranslate nohighlight">\(F\)</span>, an RREF of <span class="math notranslate nohighlight">\(A\)</span>, is equivalent to creating a
product</p>
<div class="math notranslate nohighlight">
\[E_n E_{n-1} ... E_1 A = F\]</div>
<p>where <span class="math notranslate nohighlight">\(E_n, E_{n-1}, ... , E_1\)</span> are the elimination matrices or
permutation matrices equivalent to each row-reduction step.</p>
<p>The inverse of the same product of elimination matrices gives
<span class="math notranslate nohighlight">\(C\)</span>:</p>
<div class="math notranslate nohighlight">
\[C = (E_n E_{n-1} ... E_1)^{-1}\]</div>
<p>It is not necessary, however, to actually compute the inverse:
the columns of <span class="math notranslate nohighlight">\(C\)</span> are those from the original matrix with the
same column indices as the indices of the pivot columns of <span class="math notranslate nohighlight">\(F\)</span>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixReductions.rref" title="sympy.matrices.matrices.MatrixReductions.rref"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixReductions.rref</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r549"><span class="brackets"><a class="fn-backref" href="#id25">R549</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Rank_factorization">https://en.wikipedia.org/wiki/Rank_factorization</a></p>
</dd>
<dt class="label" id="r550"><span class="brackets"><a class="fn-backref" href="#id26">R550</a></span></dt>
<dd><p>Piziak, R.; Odell, P. L. (1 June 1999).
“Full Rank Factorization of Matrices”.
Mathematics Magazine. 72 (3): 193. doi:10.2307/2690882</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.singular_value_decomposition">
<span class="sig-name descname"><span class="pre">singular_value_decomposition</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2153-L2154"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.singular_value_decomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a Condensed Singular Value decomposition.</p>
<p class="rubric">Explanation</p>
<p>A Singular Value decomposition is a decomposition in the form <span class="math notranslate nohighlight">\(A = U \Sigma V\)</span>
where</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(U, V\)</span> are column orthogonal matrix.</p></li>
<li><p><span class="math notranslate nohighlight">\(\Sigma\)</span> is a diagonal matrix, where the main diagonal contains singular
values of matrix A.</p></li>
</ul>
<p>A column orthogonal matrix satisfies
<span class="math notranslate nohighlight">\(\mathbb{I} = U^H U\)</span> while a full orthogonal matrix satisfies
relation <span class="math notranslate nohighlight">\(\mathbb{I} = U U^H = U^H U\)</span> where <span class="math notranslate nohighlight">\(\mathbb{I}\)</span> is an identity
matrix with matching dimensions.</p>
<p>For matrices which are not square or are rank-deficient, it is
sufficient to return a column orthogonal matrix because augmenting
them may introduce redundant computations.
In condensed Singular Value Decomposition we only return column orthognal
matrices because of this reason</p>
<p>If you want to augment the results to return a full orthogonal
decomposition, you should use the following procedures.</p>
<ul class="simple">
<li><p>Augment the <span class="math notranslate nohighlight">\(U , V\)</span> matrices with columns that are orthogonal to every
other columns and make it square.</p></li>
<li><p>Augument the <span class="math notranslate nohighlight">\(\Sigma\)</span> matrix with zero rows to make it have the same
shape as the original matrix.</p></li>
</ul>
<p>The procedure will be illustrated in the examples section.</p>
<p class="rubric">Examples</p>
<p>we take a full rank matrix first:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],[</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">V</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">singular_value_decomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U</span>
<span class="go">Matrix([</span>
<span class="go">[ sqrt(2)/2, sqrt(2)/2],</span>
<span class="go">[-sqrt(2)/2, sqrt(2)/2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0],</span>
<span class="go">[0, 3]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V</span>
<span class="go">Matrix([</span>
<span class="go">[-sqrt(2)/2, sqrt(2)/2],</span>
<span class="go">[ sqrt(2)/2, sqrt(2)/2]])</span>
</pre></div>
</div>
<p>If a matrix if square and full rank both U, V
are orthogonal in both directions</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">U</span> <span class="o">*</span> <span class="n">U</span><span class="o">.</span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0],</span>
<span class="go">[0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U</span><span class="o">.</span><span class="n">H</span> <span class="o">*</span> <span class="n">U</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0],</span>
<span class="go">[0, 1]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> <span class="o">*</span> <span class="n">V</span><span class="o">.</span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0],</span>
<span class="go">[0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V</span><span class="o">.</span><span class="n">H</span> <span class="o">*</span> <span class="n">V</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0],</span>
<span class="go">[0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">==</span> <span class="n">U</span> <span class="o">*</span> <span class="n">S</span> <span class="o">*</span> <span class="n">V</span><span class="o">.</span><span class="n">H</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span>
<span class="gp">... </span>        <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>        <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>        <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>        <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">V</span> <span class="o">=</span> <span class="n">C</span><span class="o">.</span><span class="n">singular_value_decomposition</span><span class="p">()</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">V</span><span class="o">.</span><span class="n">H</span> <span class="o">*</span> <span class="n">V</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> <span class="o">*</span> <span class="n">V</span><span class="o">.</span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[1/5, 0, 0, 0, 2/5],</span>
<span class="go">[  0, 1, 0, 0,   0],</span>
<span class="go">[  0, 0, 1, 0,   0],</span>
<span class="go">[  0, 0, 0, 0,   0],</span>
<span class="go">[2/5, 0, 0, 0, 4/5]])</span>
</pre></div>
</div>
<p>If you want to augment the results to be a full orthogonal
decomposition, you should augment <span class="math notranslate nohighlight">\(V\)</span> with an another orthogonal
column.</p>
<p>You are able to append an arbitrary standard basis that are linearly
independent to every other columns and you can run the Gram-Schmidt
process to make them augmented as orthogonal basis.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">V_aug</span> <span class="o">=</span> <span class="n">V</span><span class="o">.</span><span class="n">row_join</span><span class="p">(</span><span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span>
<span class="gp">... </span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">]])</span><span class="o">.</span><span class="n">H</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V_aug</span> <span class="o">=</span> <span class="n">V_aug</span><span class="o">.</span><span class="n">QRdecomposition</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V_aug</span>
<span class="go">Matrix([</span>
<span class="go">[0,   sqrt(5)/5, 0, -2*sqrt(5)/5, 0],</span>
<span class="go">[1,           0, 0,            0, 0],</span>
<span class="go">[0,           0, 1,            0, 0],</span>
<span class="go">[0,           0, 0,            0, 1],</span>
<span class="go">[0, 2*sqrt(5)/5, 0,    sqrt(5)/5, 0]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V_aug</span><span class="o">.</span><span class="n">H</span> <span class="o">*</span> <span class="n">V_aug</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0, 0, 0],</span>
<span class="go">[0, 1, 0, 0, 0],</span>
<span class="go">[0, 0, 1, 0, 0],</span>
<span class="go">[0, 0, 0, 1, 0],</span>
<span class="go">[0, 0, 0, 0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V_aug</span> <span class="o">*</span> <span class="n">V_aug</span><span class="o">.</span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0, 0, 0],</span>
<span class="go">[0, 1, 0, 0, 0],</span>
<span class="go">[0, 0, 1, 0, 0],</span>
<span class="go">[0, 0, 0, 1, 0],</span>
<span class="go">[0, 0, 0, 0, 1]])</span>
</pre></div>
</div>
<p>Similarly we augment U</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">U_aug</span> <span class="o">=</span> <span class="n">U</span><span class="o">.</span><span class="n">row_join</span><span class="p">(</span><span class="n">Matrix</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U_aug</span> <span class="o">=</span> <span class="n">U_aug</span><span class="o">.</span><span class="n">QRdecomposition</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U_aug</span>
<span class="go">Matrix([</span>
<span class="go">[0, 1, 0, 0],</span>
<span class="go">[0, 0, 1, 0],</span>
<span class="go">[0, 0, 0, 1],</span>
<span class="go">[1, 0, 0, 0]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">U_aug</span><span class="o">.</span><span class="n">H</span> <span class="o">*</span> <span class="n">U_aug</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0, 0],</span>
<span class="go">[0, 1, 0, 0],</span>
<span class="go">[0, 0, 1, 0],</span>
<span class="go">[0, 0, 0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U_aug</span> <span class="o">*</span> <span class="n">U_aug</span><span class="o">.</span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0, 0],</span>
<span class="go">[0, 1, 0, 0],</span>
<span class="go">[0, 0, 1, 0],</span>
<span class="go">[0, 0, 0, 1]])</span>
</pre></div>
</div>
<p>We add 2 zero columns and one row to S</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S_aug</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">col_join</span><span class="p">(</span><span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S_aug</span> <span class="o">=</span> <span class="n">S_aug</span><span class="o">.</span><span class="n">row_join</span><span class="p">(</span><span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]])</span><span class="o">.</span><span class="n">H</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S_aug</span>
<span class="go">Matrix([</span>
<span class="go">[2,       0, 0, 0, 0],</span>
<span class="go">[0, sqrt(5), 0, 0, 0],</span>
<span class="go">[0,       0, 3, 0, 0],</span>
<span class="go">[0,       0, 0, 0, 0]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">U_aug</span> <span class="o">*</span> <span class="n">S_aug</span> <span class="o">*</span> <span class="n">V_aug</span><span class="o">.</span><span class="n">H</span> <span class="o">==</span> <span class="n">C</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.solve">
<span class="sig-name descname"><span class="pre">solve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'GJ'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2189-L2190"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.solve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solves linear equation where the unique solution exists.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rhs</strong> : Matrix</p>
<blockquote>
<div><p>Vector representing the right hand side of the linear equation.</p>
</div></blockquote>
<p><strong>method</strong> : string, optional</p>
<blockquote>
<div><p>If set to <code class="docutils literal notranslate"><span class="pre">'GJ'</span></code> or <code class="docutils literal notranslate"><span class="pre">'GE'</span></code>, the Gauss-Jordan elimination will be
used, which is implemented in the routine <code class="docutils literal notranslate"><span class="pre">gauss_jordan_solve</span></code>.</p>
<p>If set to <code class="docutils literal notranslate"><span class="pre">'LU'</span></code>, <code class="docutils literal notranslate"><span class="pre">LUsolve</span></code> routine will be used.</p>
<p>If set to <code class="docutils literal notranslate"><span class="pre">'QR'</span></code>, <code class="docutils literal notranslate"><span class="pre">QRsolve</span></code> routine will be used.</p>
<p>If set to <code class="docutils literal notranslate"><span class="pre">'PINV'</span></code>, <code class="docutils literal notranslate"><span class="pre">pinv_solve</span></code> routine will be used.</p>
<p>It also supports the methods available for special linear systems</p>
<p>For positive definite systems:</p>
<p>If set to <code class="docutils literal notranslate"><span class="pre">'CH'</span></code>, <code class="docutils literal notranslate"><span class="pre">cholesky_solve</span></code> routine will be used.</p>
<p>If set to <code class="docutils literal notranslate"><span class="pre">'LDL'</span></code>, <code class="docutils literal notranslate"><span class="pre">LDLsolve</span></code> routine will be used.</p>
<p>To use a different method and to compute the solution via the
inverse, use a method defined in the .inv() docstring.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>solutions</strong> : Matrix</p>
<blockquote>
<div><p>Vector representing the solution.</p>
</div></blockquote>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><strong>ValueError</strong></p>
<blockquote>
<div><p>If there is not a unique solution then a <code class="docutils literal notranslate"><span class="pre">ValueError</span></code> will be
raised.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">M</span></code> is not square, a <code class="docutils literal notranslate"><span class="pre">ValueError</span></code> and a different routine
for solving the system will be suggested.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.solve_least_squares">
<span class="sig-name descname"><span class="pre">solve_least_squares</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'CH'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2192-L2193"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.solve_least_squares" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the least-square fit to the data.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rhs</strong> : Matrix</p>
<blockquote>
<div><p>Vector representing the right hand side of the linear equation.</p>
</div></blockquote>
<p><strong>method</strong> : string or boolean, optional</p>
<blockquote>
<div><p>If set to <code class="docutils literal notranslate"><span class="pre">'CH'</span></code>, <code class="docutils literal notranslate"><span class="pre">cholesky_solve</span></code> routine will be used.</p>
<p>If set to <code class="docutils literal notranslate"><span class="pre">'LDL'</span></code>, <code class="docutils literal notranslate"><span class="pre">LDLsolve</span></code> routine will be used.</p>
<p>If set to <code class="docutils literal notranslate"><span class="pre">'QR'</span></code>, <code class="docutils literal notranslate"><span class="pre">QRsolve</span></code> routine will be used.</p>
<p>If set to <code class="docutils literal notranslate"><span class="pre">'PINV'</span></code>, <code class="docutils literal notranslate"><span class="pre">pinv_solve</span></code> routine will be used.</p>
<p>Otherwise, the conjugate of <code class="docutils literal notranslate"><span class="pre">M</span></code> will be used to create a system
of equations that is passed to <code class="docutils literal notranslate"><span class="pre">solve</span></code> along with the hint
defined by <code class="docutils literal notranslate"><span class="pre">method</span></code>.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>solutions</strong> : Matrix</p>
<blockquote>
<div><p>Vector representing the solution.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">ones</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">row_join</span><span class="p">(</span><span class="n">B</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span>
<span class="go">Matrix([</span>
<span class="go">[1, 2],</span>
<span class="go">[2, 3],</span>
<span class="go">[3, 4]])</span>
</pre></div>
</div>
<p>If each line of S represent coefficients of Ax + By
and x and y are [2, 3] then S*xy is:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">S</span><span class="o">*</span><span class="n">Matrix</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]);</span> <span class="n">r</span>
<span class="go">Matrix([</span>
<span class="go">[ 8],</span>
<span class="go">[13],</span>
<span class="go">[18]])</span>
</pre></div>
</div>
<p>But let’s add 1 to the middle value and then solve for the
least-squares value of xy:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">xy</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">solve_least_squares</span><span class="p">(</span><span class="n">Matrix</span><span class="p">([</span><span class="mi">8</span><span class="p">,</span> <span class="mi">14</span><span class="p">,</span> <span class="mi">18</span><span class="p">]));</span> <span class="n">xy</span>
<span class="go">Matrix([</span>
<span class="go">[ 5/3],</span>
<span class="go">[10/3]])</span>
</pre></div>
</div>
<p>The error is given by S*xy - r:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">*</span><span class="n">xy</span> <span class="o">-</span> <span class="n">r</span>
<span class="go">Matrix([</span>
<span class="go">[1/3],</span>
<span class="go">[1/3],</span>
<span class="go">[1/3]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">norm</span><span class="p">()</span><span class="o">.</span><span class="n">n</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.58</span>
</pre></div>
</div>
<p>If a different xy is used, the norm will be higher:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">xy</span> <span class="o">+=</span> <span class="n">ones</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">10</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">S</span><span class="o">*</span><span class="n">xy</span> <span class="o">-</span> <span class="n">r</span><span class="p">)</span><span class="o">.</span><span class="n">norm</span><span class="p">()</span><span class="o">.</span><span class="n">n</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">1.5</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.strongly_connected_components">
<span class="sig-name descname"><span class="pre">strongly_connected_components</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2232-L2233"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.strongly_connected_components" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of strongly connected vertices of the graph when
a square matrix is viewed as a weighted graph.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">44</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">43</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">66</span><span class="p">,</span> <span class="mi">62</span><span class="p">,</span> <span class="mi">61</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">68</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">60</span><span class="p">,</span> <span class="mi">67</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">22</span><span class="p">,</span> <span class="mi">21</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">34</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">33</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">35</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">86</span><span class="p">,</span> <span class="mi">82</span><span class="p">,</span> <span class="mi">81</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">88</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">87</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">54</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">53</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">55</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">76</span><span class="p">,</span> <span class="mi">72</span><span class="p">,</span> <span class="mi">71</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">78</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span> <span class="mi">77</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">strongly_connected_components</span><span class="p">()</span>
<span class="go">[[0, 4, 6], [2, 3, 7], [1, 5, 8]]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.strongly_connected_components_decomposition">
<span class="sig-name descname"><span class="pre">strongly_connected_components_decomposition</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lower</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2235-L2236"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.strongly_connected_components_decomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Decomposes a square matrix into block triangular form only
using the permutations.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>lower</strong> : bool</p>
<blockquote>
<div><p>Makes <span class="math notranslate nohighlight">\(B\)</span> lower block triangular when <code class="docutils literal notranslate"><span class="pre">True</span></code>.
Otherwise, makes <span class="math notranslate nohighlight">\(B\)</span> upper block triangular.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>P, B</strong> : PermutationMatrix, BlockMatrix</p>
<blockquote>
<div><p><em>P</em> is a permutation matrix for the similarity transform
as in the explanation. And <em>B</em> is the block triangular matrix of
the result of the permutation.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The decomposition is in a form of <span class="math notranslate nohighlight">\(A = P^{-1} B P\)</span> where <span class="math notranslate nohighlight">\(P\)</span> is a
permutation matrix and <span class="math notranslate nohighlight">\(B\)</span> is a block diagonal matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">pprint</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">44</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">43</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">66</span><span class="p">,</span> <span class="mi">62</span><span class="p">,</span> <span class="mi">61</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">68</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">60</span><span class="p">,</span> <span class="mi">67</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">22</span><span class="p">,</span> <span class="mi">21</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">34</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">33</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">35</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">86</span><span class="p">,</span> <span class="mi">82</span><span class="p">,</span> <span class="mi">81</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">88</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">87</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">54</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">53</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">55</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">76</span><span class="p">,</span> <span class="mi">72</span><span class="p">,</span> <span class="mi">71</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">78</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span> <span class="mi">77</span><span class="p">]])</span>
</pre></div>
</div>
<p>A lower block triangular decomposition:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">,</span> <span class="n">B</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">strongly_connected_components_decomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">P</span><span class="p">)</span>
<span class="go">PermutationMatrix((8)(1 4 3 2 6)(5 7))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="go">[[44  43  45]   [0  0  0]     [0  0  0]  ]</span>
<span class="go">[[          ]   [       ]     [       ]  ]</span>
<span class="go">[[34  33  35]   [0  0  0]     [0  0  0]  ]</span>
<span class="go">[[          ]   [       ]     [       ]  ]</span>
<span class="go">[[54  53  55]   [0  0  0]     [0  0  0]  ]</span>
<span class="go">[                                        ]</span>
<span class="go">[ [0  0  0]    [22  21  20]   [0  0  0]  ]</span>
<span class="go">[ [       ]    [          ]   [       ]  ]</span>
<span class="go">[ [0  0  0]    [12  11  10]   [0  0  0]  ]</span>
<span class="go">[ [       ]    [          ]   [       ]  ]</span>
<span class="go">[ [0  0  0]    [2   1   0 ]   [0  0  0]  ]</span>
<span class="go">[                                        ]</span>
<span class="go">[ [0  0  0]    [62  61  60]  [66  68  67]]</span>
<span class="go">[ [       ]    [          ]  [          ]]</span>
<span class="go">[ [0  0  0]    [82  81  80]  [86  88  87]]</span>
<span class="go">[ [       ]    [          ]  [          ]]</span>
<span class="go">[ [0  0  0]    [72  71  70]  [76  78  77]]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">B</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="o">.</span><span class="n">T</span> <span class="o">*</span> <span class="n">B</span> <span class="o">*</span> <span class="n">P</span> <span class="o">==</span> <span class="n">A</span>
<span class="go">True</span>
</pre></div>
</div>
<p>An upper block triangular decomposition:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">,</span> <span class="n">B</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">strongly_connected_components_decomposition</span><span class="p">(</span><span class="n">lower</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">P</span><span class="p">)</span>
<span class="go">PermutationMatrix((0 1 5 7 4 3 2 8 6))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="go">[[66  68  67]  [62  61  60]   [0  0  0]  ]</span>
<span class="go">[[          ]  [          ]   [       ]  ]</span>
<span class="go">[[86  88  87]  [82  81  80]   [0  0  0]  ]</span>
<span class="go">[[          ]  [          ]   [       ]  ]</span>
<span class="go">[[76  78  77]  [72  71  70]   [0  0  0]  ]</span>
<span class="go">[                                        ]</span>
<span class="go">[ [0  0  0]    [22  21  20]   [0  0  0]  ]</span>
<span class="go">[ [       ]    [          ]   [       ]  ]</span>
<span class="go">[ [0  0  0]    [12  11  10]   [0  0  0]  ]</span>
<span class="go">[ [       ]    [          ]   [       ]  ]</span>
<span class="go">[ [0  0  0]    [2   1   0 ]   [0  0  0]  ]</span>
<span class="go">[                                        ]</span>
<span class="go">[ [0  0  0]     [0  0  0]    [44  43  45]]</span>
<span class="go">[ [       ]     [       ]    [          ]]</span>
<span class="go">[ [0  0  0]     [0  0  0]    [34  33  35]]</span>
<span class="go">[ [       ]     [       ]    [          ]]</span>
<span class="go">[ [0  0  0]     [0  0  0]    [54  53  55]]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">B</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="o">.</span><span class="n">T</span> <span class="o">*</span> <span class="n">B</span> <span class="o">*</span> <span class="n">P</span> <span class="o">==</span> <span class="n">A</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.table">
<span class="sig-name descname"><span class="pre">table</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">printer</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rowstart</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'['</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rowend</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">']'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rowsep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'\n'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">colsep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">',</span> <span class="pre">'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">align</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'right'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2052-L2128"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.table" title="Permalink to this definition">¶</a></dt>
<dd><p>String form of Matrix as a table.</p>
<p><code class="docutils literal notranslate"><span class="pre">printer</span></code> is the printer to use for on the elements (generally
something like StrPrinter())</p>
<p><code class="docutils literal notranslate"><span class="pre">rowstart</span></code> is the string used to start each row (by default ‘[‘).</p>
<p><code class="docutils literal notranslate"><span class="pre">rowend</span></code> is the string used to end each row (by default ‘]’).</p>
<p><code class="docutils literal notranslate"><span class="pre">rowsep</span></code> is the string used to separate rows (by default a newline).</p>
<p><code class="docutils literal notranslate"><span class="pre">colsep</span></code> is the string used to separate columns (by default ‘, ‘).</p>
<p><code class="docutils literal notranslate"><span class="pre">align</span></code> defines how the elements are aligned. Must be one of ‘left’,
‘right’, or ‘center’.  You can also use ‘&lt;’, ‘&gt;’, and ‘^’ to mean the
same thing, respectively.</p>
<p>This is used by the string printer for Matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.str</span> <span class="kn">import</span> <span class="n">StrPrinter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">33</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">printer</span> <span class="o">=</span> <span class="n">StrPrinter</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">printer</span><span class="p">)</span>
<span class="go">&#39;[  1, 2]\n[-33, 4]&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">printer</span><span class="p">))</span>
<span class="go">[  1, 2]</span>
<span class="go">[-33, 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">printer</span><span class="p">,</span> <span class="n">rowsep</span><span class="o">=</span><span class="s1">&#39;,</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">))</span>
<span class="go">[  1, 2],</span>
<span class="go">[-33, 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;[</span><span class="si">%s</span><span class="s1">]&#39;</span> <span class="o">%</span> <span class="n">M</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">printer</span><span class="p">,</span> <span class="n">rowsep</span><span class="o">=</span><span class="s1">&#39;,</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">))</span>
<span class="go">[[  1, 2],</span>
<span class="go">[-33, 4]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">printer</span><span class="p">,</span> <span class="n">colsep</span><span class="o">=</span><span class="s1">&#39; &#39;</span><span class="p">))</span>
<span class="go">[  1 2]</span>
<span class="go">[-33 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">printer</span><span class="p">,</span> <span class="n">align</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">))</span>
<span class="go">[ 1 , 2]</span>
<span class="go">[-33, 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">printer</span><span class="p">,</span> <span class="n">rowstart</span><span class="o">=</span><span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="n">rowend</span><span class="o">=</span><span class="s1">&#39;}&#39;</span><span class="p">))</span>
<span class="go">{  1, 2}</span>
<span class="go">{-33, 4}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.upper_hessenberg_decomposition">
<span class="sig-name descname"><span class="pre">upper_hessenberg_decomposition</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2159-L2160"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.upper_hessenberg_decomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts a matrix into Hessenberg matrix H</p>
<p>Returns 2 matrices H, P s.t.
<span class="math notranslate nohighlight">\(P H P^{T} = A\)</span>, where H is an upper hessenberg matrix
and P is an orthogonal matrix</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">],</span>
<span class="gp">... </span>    <span class="p">[</span><span class="mi">4</span><span class="p">,</span><span class="o">-</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">],</span>
<span class="gp">... </span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span><span class="p">,</span> <span class="n">P</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">upper_hessenberg_decomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span>
<span class="go">Matrix([</span>
<span class="go">[1,    6/5,    17/5],</span>
<span class="go">[5, 213/25, -134/25],</span>
<span class="go">[0, 216/25,  137/25]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span>
<span class="go">Matrix([</span>
<span class="go">[1,    0,   0],</span>
<span class="go">[0, -3/5, 4/5],</span>
<span class="go">[0,  4/5, 3/5]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">*</span> <span class="n">H</span> <span class="o">*</span> <span class="n">P</span><span class="o">.</span><span class="n">H</span> <span class="o">==</span> <span class="n">A</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="footnote brackets">
<dt class="label" id="id27"><span class="brackets">1</span></dt>
<dd><p><a class="reference external" href="https://mathworld.wolfram.com/HessenbergDecomposition.html">https://mathworld.wolfram.com/HessenbergDecomposition.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixBase.upper_triangular_solve">
<span class="sig-name descname"><span class="pre">upper_triangular_solve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2168-L2169"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixBase.upper_triangular_solve" title="Permalink to this definition">¶</a></dt>
<dd><p>Solves <code class="docutils literal notranslate"><span class="pre">Ax</span> <span class="pre">=</span> <span class="pre">B</span></code>, where A is an upper triangular matrix.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.lower_triangular_solve" title="sympy.matrices.matrices.MatrixBase.lower_triangular_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lower_triangular_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.gauss_jordan_solve" title="sympy.matrices.matrices.MatrixBase.gauss_jordan_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">gauss_jordan_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.cholesky_solve" title="sympy.matrices.matrices.MatrixBase.cholesky_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cholesky_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.diagonal_solve" title="sympy.matrices.matrices.MatrixBase.diagonal_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonal_solve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LDLsolve" title="sympy.matrices.matrices.MatrixBase.LDLsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LDLsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.LUsolve" title="sympy.matrices.matrices.MatrixBase.LUsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LUsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.QRsolve" title="sympy.matrices.matrices.MatrixBase.QRsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">QRsolve</span></code></a>, <a class="reference internal" href="#sympy.matrices.matrices.MatrixBase.pinv_solve" title="sympy.matrices.matrices.MatrixBase.pinv_solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pinv_solve</span></code></a></p>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="matrix-exceptions-reference">
<h2>Matrix Exceptions Reference<a class="headerlink" href="#matrix-exceptions-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.matrices.MatrixError">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">MatrixError</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/common.py#L35-L36"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.MatrixError" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.matrices.ShapeError">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">ShapeError</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/common.py#L39-L41"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.ShapeError" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrong matrix shape</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.matrices.NonSquareMatrixError">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">NonSquareMatrixError</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/common.py#L44-L45"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.NonSquareMatrixError" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</section>
<section id="matrix-functions-reference">
<h2>Matrix Functions Reference<a class="headerlink" href="#matrix-functions-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.matrix_multiply_elementwise">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">matrix_multiply_elementwise</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">A</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">B</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L602-L619"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.matrix_multiply_elementwise" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the Hadamard product (elementwise product) of A and B</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">matrix_multiply_elementwise</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">100</span><span class="p">],</span> <span class="p">[</span><span class="mi">100</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">matrix_multiply_elementwise</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[  0, 10, 200],</span>
<span class="go">[300, 40,   5]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.__mul__" title="sympy.matrices.common.MatrixCommon.__mul__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.common.MatrixCommon.__mul__</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.zeros">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">zeros</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L748-L763"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.zeros" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a matrix of zeros with <code class="docutils literal notranslate"><span class="pre">rows</span></code> rows and <code class="docutils literal notranslate"><span class="pre">cols</span></code> columns;
if <code class="docutils literal notranslate"><span class="pre">cols</span></code> is omitted a square matrix will be returned.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.dense.ones" title="sympy.matrices.dense.ones"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ones</span></code></a>, <a class="reference internal" href="#sympy.matrices.dense.eye" title="sympy.matrices.dense.eye"><code class="xref py py-obj docutils literal notranslate"><span class="pre">eye</span></code></a>, <a class="reference internal" href="#sympy.matrices.dense.diag" title="sympy.matrices.dense.diag"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diag</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.ones">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">ones</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L622-L637"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.ones" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a matrix of ones with <code class="docutils literal notranslate"><span class="pre">rows</span></code> rows and <code class="docutils literal notranslate"><span class="pre">cols</span></code> columns;
if <code class="docutils literal notranslate"><span class="pre">cols</span></code> is omitted a square matrix will be returned.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.dense.zeros" title="sympy.matrices.dense.zeros"><code class="xref py py-obj docutils literal notranslate"><span class="pre">zeros</span></code></a>, <a class="reference internal" href="#sympy.matrices.dense.eye" title="sympy.matrices.dense.eye"><code class="xref py py-obj docutils literal notranslate"><span class="pre">eye</span></code></a>, <a class="reference internal" href="#sympy.matrices.dense.diag" title="sympy.matrices.dense.diag"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diag</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.eye">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">eye</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L413-L424"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.eye" title="Permalink to this definition">¶</a></dt>
<dd><p>Create square identity matrix n x n</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.dense.diag" title="sympy.matrices.dense.diag"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diag</span></code></a>, <a class="reference internal" href="#sympy.matrices.dense.zeros" title="sympy.matrices.dense.zeros"><code class="xref py py-obj docutils literal notranslate"><span class="pre">zeros</span></code></a>, <a class="reference internal" href="#sympy.matrices.dense.ones" title="sympy.matrices.dense.ones"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ones</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.diag">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">diag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">values</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">strict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">unpack</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L427-L461"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.diag" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a matrix with the provided values placed on the
diagonal. If non-square matrices are included, they will
produce a block-diagonal matrix.</p>
<p class="rubric">Examples</p>
<p>This version of diag is a thin wrapper to Matrix.diag that differs
in that it treats all lists like matrices – even when a single list
is given. If this is not desired, either put a <span class="math notranslate nohighlight">\(*\)</span> before the list or
set <span class="math notranslate nohighlight">\(unpack=True\)</span>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">diag</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">diag</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="n">unpack</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>  <span class="c1"># = diag(1,2,3) or diag(*[1,2,3])</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 2, 0],</span>
<span class="go">[0, 0, 3]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">diag</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>  <span class="c1"># a column vector</span>
<span class="go">Matrix([</span>
<span class="go">[1],</span>
<span class="go">[2],</span>
<span class="go">[3]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.eye" title="sympy.matrices.common.MatrixCommon.eye"><code class="xref py py-obj docutils literal notranslate"><span class="pre">common.MatrixCommon.eye</span></code></a>, <a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.diagonal" title="sympy.matrices.common.MatrixCommon.diagonal"><code class="xref py py-obj docutils literal notranslate"><span class="pre">common.MatrixCommon.diagonal</span></code></a>, <a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.diag" title="sympy.matrices.common.MatrixCommon.diag"><code class="xref py py-obj docutils literal notranslate"><span class="pre">common.MatrixCommon.diag</span></code></a>, <a class="reference internal" href="expressions.html#sympy.matrices.expressions.blockmatrix.BlockMatrix" title="sympy.matrices.expressions.blockmatrix.BlockMatrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expressions.blockmatrix.BlockMatrix</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.jordan_cell">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">jordan_cell</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">eigenval</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L582-L599"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.jordan_cell" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Jordan block:</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">jordan_cell</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">jordan_cell</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[x, 1, 0, 0],</span>
<span class="go">[0, x, 1, 0],</span>
<span class="go">[0, 0, x, 1],</span>
<span class="go">[0, 0, 0, x]])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.hessian">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">hessian</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">varlist</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">constraints</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">[]</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L505-L579"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.hessian" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute Hessian matrix for a function f wrt parameters in varlist
which may be given as a sequence or a row/column vector. A list of
constraints may optionally be given.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Function</span><span class="p">,</span> <span class="n">hessian</span><span class="p">,</span> <span class="n">pprint</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g1</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;g&#39;</span><span class="p">)(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g2</span> <span class="o">=</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">hessian</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="p">[</span><span class="n">g1</span><span class="p">,</span> <span class="n">g2</span><span class="p">]))</span>
<span class="go">[                   d               d            ]</span>
<span class="go">[     0        0    --(g(x, y))     --(g(x, y))  ]</span>
<span class="go">[                   dx              dy           ]</span>
<span class="go">[                                                ]</span>
<span class="go">[     0        0        2*x              3       ]</span>
<span class="go">[                                                ]</span>
<span class="go">[                     2               2          ]</span>
<span class="go">[d                   d               d           ]</span>
<span class="go">[--(g(x, y))  2*x   ---(f(x, y))   -----(f(x, y))]</span>
<span class="go">[dx                   2            dy dx         ]</span>
<span class="go">[                   dx                           ]</span>
<span class="go">[                                                ]</span>
<span class="go">[                     2               2          ]</span>
<span class="go">[d                   d               d           ]</span>
<span class="go">[--(g(x, y))   3   -----(f(x, y))   ---(f(x, y)) ]</span>
<span class="go">[dy                dy dx              2          ]</span>
<span class="go">[                                   dy           ]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixCalculus.jacobian" title="sympy.matrices.matrices.MatrixCalculus.jacobian"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixCalculus.jacobian</span></code></a>, <a class="reference internal" href="#sympy.matrices.dense.wronskian" title="sympy.matrices.dense.wronskian"><code class="xref py py-obj docutils literal notranslate"><span class="pre">wronskian</span></code></a></p>
</div>
<p class="rubric">References</p>
<p><a class="reference external" href="https://en.wikipedia.org/wiki/Hessian_matrix">https://en.wikipedia.org/wiki/Hessian_matrix</a></p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.GramSchmidt">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">GramSchmidt</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">vlist</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">orthonormal</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L464-L502"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.GramSchmidt" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply the Gram-Schmidt process to a set of vectors.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>vlist</strong> : List of Matrix</p>
<blockquote>
<div><p>Vectors to be orthogonalized for.</p>
</div></blockquote>
<p><strong>orthonormal</strong> : Bool, optional</p>
<blockquote>
<div><p>If true, return an orthonormal basis.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>vlist</strong> : List of Matrix</p>
<blockquote>
<div><p>Orthogonalized vectors</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>This routine is mostly duplicate from <code class="docutils literal notranslate"><span class="pre">Matrix.orthogonalize</span></code>,
except for some difference that this always raises error when
linearly dependent vectors are found, and the keyword <code class="docutils literal notranslate"><span class="pre">normalize</span></code>
has been named as <code class="docutils literal notranslate"><span class="pre">orthonormal</span></code> in this function.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixSubspaces.orthogonalize" title="sympy.matrices.matrices.MatrixSubspaces.orthogonalize"><code class="xref py py-obj docutils literal notranslate"><span class="pre">matrices.MatrixSubspaces.orthogonalize</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r551"><span class="brackets"><a class="fn-backref" href="#id28">R551</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Gram–Schmidt_process">https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.wronskian">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">wronskian</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">functions</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">var</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'bareiss'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L716-L745"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.wronskian" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute Wronskian for [] of functions</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>                 <span class="o">|</span> <span class="n">f1</span>       <span class="n">f2</span>        <span class="o">...</span>   <span class="n">fn</span>      <span class="o">|</span>
                 <span class="o">|</span> <span class="n">f1</span><span class="s1">&#39;      f2&#39;</span>       <span class="o">...</span>   <span class="n">fn</span><span class="s1">&#39;     |</span>
                 <span class="o">|</span>  <span class="o">.</span>        <span class="o">.</span>        <span class="o">.</span>      <span class="o">.</span>      <span class="o">|</span>
<span class="n">W</span><span class="p">(</span><span class="n">f1</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span> <span class="n">fn</span><span class="p">)</span> <span class="o">=</span> <span class="o">|</span>  <span class="o">.</span>        <span class="o">.</span>         <span class="o">.</span>     <span class="o">.</span>      <span class="o">|</span>
                 <span class="o">|</span>  <span class="o">.</span>        <span class="o">.</span>          <span class="o">.</span>    <span class="o">.</span>      <span class="o">|</span>
                 <span class="o">|</span>  <span class="p">(</span><span class="n">n</span><span class="p">)</span>      <span class="p">(</span><span class="n">n</span><span class="p">)</span>            <span class="p">(</span><span class="n">n</span><span class="p">)</span>     <span class="o">|</span>
                 <span class="o">|</span> <span class="n">D</span>   <span class="p">(</span><span class="n">f1</span><span class="p">)</span> <span class="n">D</span>   <span class="p">(</span><span class="n">f2</span><span class="p">)</span>  <span class="o">...</span>  <span class="n">D</span>   <span class="p">(</span><span class="n">fn</span><span class="p">)</span> <span class="o">|</span>
</pre></div>
</div>
<p>see: <a class="reference external" href="https://en.wikipedia.org/wiki/Wronskian">https://en.wikipedia.org/wiki/Wronskian</a></p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.matrices.MatrixCalculus.jacobian" title="sympy.matrices.matrices.MatrixCalculus.jacobian"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixCalculus.jacobian</span></code></a>, <a class="reference internal" href="#sympy.matrices.dense.hessian" title="sympy.matrices.dense.hessian"><code class="xref py py-obj docutils literal notranslate"><span class="pre">hessian</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.casoratian">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">casoratian</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">seqs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">zero</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L370-L410"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.casoratian" title="Permalink to this definition">¶</a></dt>
<dd><p>Given linear difference operator L of order ‘k’ and homogeneous
equation Ly = 0 we want to compute kernel of L, which is a set
of ‘k’ sequences: a(n), b(n), … z(n).</p>
<p>Solutions of L are linearly independent iff their Casoratian,
denoted as C(a, b, …, z), do not vanish for n = 0.</p>
<p>Casoratian is defined by k x k determinant:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">+</span>  <span class="n">a</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>     <span class="n">b</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>     <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="n">z</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>     <span class="o">+</span>
<span class="o">|</span>  <span class="n">a</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>   <span class="n">b</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>   <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="n">z</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>   <span class="o">|</span>
<span class="o">|</span>    <span class="o">.</span>         <span class="o">.</span>     <span class="o">.</span>        <span class="o">.</span>     <span class="o">|</span>
<span class="o">|</span>    <span class="o">.</span>         <span class="o">.</span>       <span class="o">.</span>      <span class="o">.</span>     <span class="o">|</span>
<span class="o">|</span>    <span class="o">.</span>         <span class="o">.</span>         <span class="o">.</span>    <span class="o">.</span>     <span class="o">|</span>
<span class="o">+</span>  <span class="n">a</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="n">k</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="n">b</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="n">k</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="n">z</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="n">k</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span>
</pre></div>
</div>
<p>It proves very useful in rsolve_hyper() where it is applied
to a generating set of a recurrence to factor out linearly
dependent solutions and return a basis:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">casoratian</span><span class="p">,</span> <span class="n">factorial</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Exponential and factorial are linearly independent:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">casoratian</span><span class="p">([</span><span class="mi">2</span><span class="o">**</span><span class="n">n</span><span class="p">,</span> <span class="n">factorial</span><span class="p">(</span><span class="n">n</span><span class="p">)],</span> <span class="n">n</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.randMatrix">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">randMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">r</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">min</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">99</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">symmetric</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">percent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">100</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prng</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L640-L713"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.randMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Create random matrix with dimensions <code class="docutils literal notranslate"><span class="pre">r</span></code> x <code class="docutils literal notranslate"><span class="pre">c</span></code>. If <code class="docutils literal notranslate"><span class="pre">c</span></code> is omitted
the matrix will be square. If <code class="docutils literal notranslate"><span class="pre">symmetric</span></code> is True the matrix must be
square. If <code class="docutils literal notranslate"><span class="pre">percent</span></code> is less than 100 then only approximately the given
percentage of elements will be non-zero.</p>
<p>The pseudo-random number generator used to generate matrix is chosen in the
following way.</p>
<ul class="simple">
<li><p>If <code class="docutils literal notranslate"><span class="pre">prng</span></code> is supplied, it will be used as random number generator.
It should be an instance of <code class="docutils literal notranslate"><span class="pre">random.Random</span></code>, or at least have
<code class="docutils literal notranslate"><span class="pre">randint</span></code> and <code class="docutils literal notranslate"><span class="pre">shuffle</span></code> methods with same signatures.</p></li>
<li><p>if <code class="docutils literal notranslate"><span class="pre">prng</span></code> is not supplied but <code class="docutils literal notranslate"><span class="pre">seed</span></code> is supplied, then new
<code class="docutils literal notranslate"><span class="pre">random.Random</span></code> with given <code class="docutils literal notranslate"><span class="pre">seed</span></code> will be created;</p></li>
<li><p>otherwise, a new <code class="docutils literal notranslate"><span class="pre">random.Random</span></code> with default seed will be used.</p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">randMatrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">randMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> 
<span class="go">[25, 45, 27]</span>
<span class="go">[44, 54,  9]</span>
<span class="go">[23, 96, 46]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">randMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> 
<span class="go">[87, 29]</span>
<span class="go">[23, 37]</span>
<span class="go">[90, 26]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">randMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> 
<span class="go">[0, 2, 0]</span>
<span class="go">[2, 0, 1]</span>
<span class="go">[0, 0, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">randMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">symmetric</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> 
<span class="go">[85, 26, 29]</span>
<span class="go">[26, 71, 43]</span>
<span class="go">[29, 43, 57]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">randMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">randMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">==</span> <span class="n">B</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">==</span> <span class="n">randMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">randMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">symmetric</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">percent</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span> 
<span class="go">[77, 70,  0],</span>
<span class="go">[70,  0,  0],</span>
<span class="go">[ 0,  0, 88]</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="numpy-utility-functions-reference">
<h2>Numpy Utility Functions Reference<a class="headerlink" href="#numpy-utility-functions-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.list2numpy">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">list2numpy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">l</span></em>, <em class="sig-param"><span class="pre">dtype=&lt;class</span> <span class="pre">'object'&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L133-L145"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.list2numpy" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts python list of SymPy expressions to a NumPy array.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.dense.matrix2numpy" title="sympy.matrices.dense.matrix2numpy"><code class="xref py py-obj docutils literal notranslate"><span class="pre">matrix2numpy</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.matrix2numpy">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">matrix2numpy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">m</span></em>, <em class="sig-param"><span class="pre">dtype=&lt;class</span> <span class="pre">'object'&gt;</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L148-L161"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.matrix2numpy" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts SymPy’s matrix to a NumPy array.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.dense.list2numpy" title="sympy.matrices.dense.list2numpy"><code class="xref py py-obj docutils literal notranslate"><span class="pre">list2numpy</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.symarray">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">symarray</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">prefix</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L293-L363"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.symarray" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a numpy ndarray of symbols (as an object array).</p>
<p>The created symbols are named <code class="docutils literal notranslate"><span class="pre">prefix_i1_i2_</span></code>…  You should thus provide a
non-empty prefix if you want your symbols to be unique for different output
arrays, as SymPy symbols with identical names are the same object.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>prefix</strong> : string</p>
<blockquote>
<div><p>A prefix prepended to the name of every symbol.</p>
</div></blockquote>
<p><strong>shape</strong> : int or tuple</p>
<blockquote>
<div><p>Shape of the created array.  If an int, the array is one-dimensional; for
more than one dimension the shape must be a tuple.</p>
</div></blockquote>
<p><strong>**kwargs</strong> : dict</p>
<blockquote>
<div><p>keyword arguments passed on to Symbol</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>These doctests require numpy.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symarray</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symarray</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">[_0 _1 _2]</span>
</pre></div>
</div>
<p>If you want multiple symarrays to contain distinct symbols, you <em>must</em>
provide unique prefixes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">symarray</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">symarray</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">symarray</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">symarray</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">False</span>
</pre></div>
</div>
<p>Creating symarrays with a prefix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">symarray</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">[a_0 a_1 a_2]</span>
</pre></div>
</div>
<p>For more than one dimension, the shape must be given as a tuple:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">symarray</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="go">[[a_0_0 a_0_1 a_0_2]</span>
<span class="go"> [a_1_0 a_1_1 a_1_2]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symarray</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">[[[a_0_0_0 a_0_0_1]</span>
<span class="go">  [a_0_1_0 a_0_1_1]</span>
<span class="go">  [a_0_2_0 a_0_2_1]]</span>

<span class="go"> [[a_1_0_0 a_1_0_1]</span>
<span class="go">  [a_1_1_0 a_1_1_1]</span>
<span class="go">  [a_1_2_0 a_1_2_1]]]</span>
</pre></div>
</div>
<p>For setting assumptions of the underlying Symbols:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">is_real</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">symarray</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)]</span>
<span class="go">[True, True]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.rot_axis1">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">rot_axis1</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L250-L290"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.rot_axis1" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a rotation matrix for a rotation of theta (in radians) about
the 1-axis.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">rot_axis1</span>
</pre></div>
</div>
<p>A rotation of pi/3 (60 degrees):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">theta</span> <span class="o">=</span> <span class="n">pi</span><span class="o">/</span><span class="mi">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rot_axis1</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1,          0,         0],</span>
<span class="go">[0,        1/2, sqrt(3)/2],</span>
<span class="go">[0, -sqrt(3)/2,       1/2]])</span>
</pre></div>
</div>
<p>If we rotate by pi/2 (90 degrees):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rot_axis1</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1,  0, 0],</span>
<span class="go">[0,  0, 1],</span>
<span class="go">[0, -1, 0]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.matrices.dense.rot_axis2" title="sympy.matrices.dense.rot_axis2"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rot_axis2</span></code></a></dt><dd><p>Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis</p>
</dd>
<dt><a class="reference internal" href="#sympy.matrices.dense.rot_axis3" title="sympy.matrices.dense.rot_axis3"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rot_axis3</span></code></a></dt><dd><p>Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.rot_axis2">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">rot_axis2</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L207-L247"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.rot_axis2" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a rotation matrix for a rotation of theta (in radians) about
the 2-axis.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">rot_axis2</span>
</pre></div>
</div>
<p>A rotation of pi/3 (60 degrees):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">theta</span> <span class="o">=</span> <span class="n">pi</span><span class="o">/</span><span class="mi">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rot_axis2</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[      1/2, 0, -sqrt(3)/2],</span>
<span class="go">[        0, 1,          0],</span>
<span class="go">[sqrt(3)/2, 0,        1/2]])</span>
</pre></div>
</div>
<p>If we rotate by pi/2 (90 degrees):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rot_axis2</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[0, 0, -1],</span>
<span class="go">[0, 1,  0],</span>
<span class="go">[1, 0,  0]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.matrices.dense.rot_axis1" title="sympy.matrices.dense.rot_axis1"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rot_axis1</span></code></a></dt><dd><p>Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis</p>
</dd>
<dt><a class="reference internal" href="#sympy.matrices.dense.rot_axis3" title="sympy.matrices.dense.rot_axis3"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rot_axis3</span></code></a></dt><dd><p>Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.dense.rot_axis3">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.dense.</span></span><span class="sig-name descname"><span class="pre">rot_axis3</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theta</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/dense.py#L164-L204"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.dense.rot_axis3" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a rotation matrix for a rotation of theta (in radians) about
the 3-axis.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">rot_axis3</span>
</pre></div>
</div>
<p>A rotation of pi/3 (60 degrees):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">theta</span> <span class="o">=</span> <span class="n">pi</span><span class="o">/</span><span class="mi">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rot_axis3</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[       1/2, sqrt(3)/2, 0],</span>
<span class="go">[-sqrt(3)/2,       1/2, 0],</span>
<span class="go">[         0,         0, 1]])</span>
</pre></div>
</div>
<p>If we rotate by pi/2 (90 degrees):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rot_axis3</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[ 0, 1, 0],</span>
<span class="go">[-1, 0, 0],</span>
<span class="go">[ 0, 0, 1]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.matrices.dense.rot_axis1" title="sympy.matrices.dense.rot_axis1"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rot_axis1</span></code></a></dt><dd><p>Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis</p>
</dd>
<dt><a class="reference internal" href="#sympy.matrices.dense.rot_axis2" title="sympy.matrices.dense.rot_axis2"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rot_axis2</span></code></a></dt><dd><p>Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.matrices.a2idx">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.matrices.</span></span><span class="sig-name descname"><span class="pre">a2idx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">j</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/matrices.py#L2290-L2296"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.matrices.a2idx" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Matrices (linear algebra)</a><ul>
<li><a class="reference internal" href="#creating-matrices">Creating Matrices</a></li>
<li><a class="reference internal" href="#basic-manipulation">Basic Manipulation</a></li>
<li><a class="reference internal" href="#operations-on-entries">Operations on entries</a></li>
<li><a class="reference internal" href="#linear-algebra">Linear algebra</a></li>
<li><a class="reference internal" href="#matrixdeterminant-class-reference">MatrixDeterminant Class Reference</a></li>
<li><a class="reference internal" href="#matrixreductions-class-reference">MatrixReductions Class Reference</a></li>
<li><a class="reference internal" href="#matrixsubspaces-class-reference">MatrixSubspaces Class Reference</a></li>
<li><a class="reference internal" href="#matrixeigen-class-reference">MatrixEigen Class Reference</a></li>
<li><a class="reference internal" href="#matrixcalculus-class-reference">MatrixCalculus Class Reference</a></li>
<li><a class="reference internal" href="#matrixbase-class-reference">MatrixBase Class Reference</a></li>
<li><a class="reference internal" href="#matrix-exceptions-reference">Matrix Exceptions Reference</a></li>
<li><a class="reference internal" href="#matrix-functions-reference">Matrix Functions Reference</a></li>
<li><a class="reference internal" href="#numpy-utility-functions-reference">Numpy Utility Functions Reference</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">Matrices</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="common.html"
                        title="next chapter">Common Matrices</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/matrices/matrices.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="common.html" title="Common Matrices"
             >next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Matrices"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Matrices</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Matrices (linear algebra)</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/matrices/matrices.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:05 GMT -->
</html>